Fix schema qualified table names usage again.

When the list of columns of the PostgreSQL target table isn't given in
the load command, pgloader will happily query the system catalogs to get
that information. The list-columns query didn't get the memo about the
qualified table name format and the with-schema macro... fix #288.
This commit is contained in:
Dimitri Fontaine 2015-09-11 11:53:28 +02:00
parent e054eb3838
commit a0dc59624c
2 changed files with 19 additions and 19 deletions

View File

@ -184,6 +184,7 @@
(defun list-columns (pgconn table-name &key schema) (defun list-columns (pgconn table-name &key schema)
"Return a list of column names for given TABLE-NAME." "Return a list of column names for given TABLE-NAME."
(with-pgsql-transaction (:pgconn pgconn) (with-pgsql-transaction (:pgconn pgconn)
(with-schema (unqualified-table-name table-name)
(pomo:query (format nil " (pomo:query (format nil "
select attname select attname
from pg_class c from pg_class c
@ -191,11 +192,12 @@
left join pg_attribute a on c.oid = a.attrelid left join pg_attribute a on c.oid = a.attrelid
join pg_type t on t.oid = a.atttypid join pg_type t on t.oid = a.atttypid
where c.oid = '~:[~*~a~;~a.~a~]'::regclass and attnum > 0 where c.oid = '~:[~*~a~;~a.~a~]'::regclass and attnum > 0
order by attnum" schema schema table-name) :column))) order by attnum" schema schema unqualified-table-name) :column))))
(defun list-indexes (table-name) (defun list-indexes (table-name)
"List all indexes for TABLE-NAME in SCHEMA. A PostgreSQL connection must "List all indexes for TABLE-NAME in SCHEMA. A PostgreSQL connection must
be already established when calling that function." be already established when calling that function."
(with-schema (unqualified-table-name table-name)
(loop :for (index-name table-name table-oid primary unique sql conname condef) (loop :for (index-name table-name table-oid primary unique sql conname condef)
:in (pomo:query (format nil " :in (pomo:query (format nil "
select i.relname, select i.relname,
@ -212,9 +214,7 @@ select i.relname,
where indrelid = '~@[~a.~]~a'::regclass" where indrelid = '~@[~a.~]~a'::regclass"
(when (typep table-name 'cons) (when (typep table-name 'cons)
(car table-name)) (car table-name))
(typecase table-name unqualified-table-name))
(cons (cdr table-name))
(string table-name))))
:collect (make-pgsql-index :name index-name :collect (make-pgsql-index :name index-name
:table-name table-name :table-name table-name
:table-oid table-oid :table-oid table-oid
@ -223,7 +223,7 @@ select i.relname,
:columns nil :columns nil
:sql sql :sql sql
:conname (unless (eq :null conname) conname) :conname (unless (eq :null conname) conname)
:condef (unless (eq :null condef) condef)))) :condef (unless (eq :null condef) condef)))))
(defun list-reserved-keywords (pgconn) (defun list-reserved-keywords (pgconn)
"Connect to PostgreSQL DBNAME and fetch reserved keywords." "Connect to PostgreSQL DBNAME and fetch reserved keywords."

View File

@ -1,6 +1,6 @@
LOAD CSV LOAD CSV
FROM INLINE FROM INLINE
INTO postgresql:///pgloader?header INTO postgresql:///pgloader?public.header
WITH truncate, WITH truncate,
fields terminated by ',', fields terminated by ',',