From a0dc59624cb1ac1ae48a766d10b5f8b967570b45 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Fri, 11 Sep 2015 11:53:28 +0200 Subject: [PATCH] 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. --- src/pgsql/queries.lisp | 36 ++++++++++++++++++------------------ test/csv-header.load | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/pgsql/queries.lisp b/src/pgsql/queries.lisp index c1114e6..e7aaeb2 100644 --- a/src/pgsql/queries.lisp +++ b/src/pgsql/queries.lisp @@ -184,20 +184,22 @@ (defun list-columns (pgconn table-name &key schema) "Return a list of column names for given TABLE-NAME." (with-pgsql-transaction (:pgconn pgconn) - (pomo:query (format nil " + (with-schema (unqualified-table-name table-name) + (pomo:query (format nil " select attname from pg_class c join pg_namespace n on n.oid = c.relnamespace left join pg_attribute a on c.oid = a.attrelid join pg_type t on t.oid = a.atttypid 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) "List all indexes for TABLE-NAME in SCHEMA. A PostgreSQL connection must be already established when calling that function." - (loop :for (index-name table-name table-oid primary unique sql conname condef) - :in (pomo:query (format nil " + (with-schema (unqualified-table-name table-name) + (loop :for (index-name table-name table-oid primary unique sql conname condef) + :in (pomo:query (format nil " select i.relname, indrelid::regclass, indrelid, @@ -210,20 +212,18 @@ select i.relname, join pg_class i ON i.oid = x.indexrelid left join pg_constraint c ON c.conindid = i.oid where indrelid = '~@[~a.~]~a'::regclass" - (when (typep table-name 'cons) - (car table-name)) - (typecase table-name - (cons (cdr table-name)) - (string table-name)))) - :collect (make-pgsql-index :name index-name - :table-name table-name - :table-oid table-oid - :primary primary - :unique unique - :columns nil - :sql sql - :conname (unless (eq :null conname) conname) - :condef (unless (eq :null condef) condef)))) + (when (typep table-name 'cons) + (car table-name)) + unqualified-table-name)) + :collect (make-pgsql-index :name index-name + :table-name table-name + :table-oid table-oid + :primary primary + :unique unique + :columns nil + :sql sql + :conname (unless (eq :null conname) conname) + :condef (unless (eq :null condef) condef))))) (defun list-reserved-keywords (pgconn) "Connect to PostgreSQL DBNAME and fetch reserved keywords." diff --git a/test/csv-header.load b/test/csv-header.load index b69d4d7..e31c78d 100644 --- a/test/csv-header.load +++ b/test/csv-header.load @@ -1,6 +1,6 @@ LOAD CSV FROM INLINE - INTO postgresql:///pgloader?header + INTO postgresql:///pgloader?public.header WITH truncate, fields terminated by ',',