From c05183fcbac2988fda56839daa1abe3426808204 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Fri, 1 Dec 2017 22:13:47 +0100 Subject: [PATCH] Implement support for Foreign Tables and Partitionned Tables. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to the way pgloader queries the PostgreSQL catalogs, it restricted the target table to be “ordinary” tables, as per the relkind description in the https://www.postgresql.org/docs/current/static/catalog-pg-class.html PostgreSQL documentation. Extend this to support relkind of 'r', 'f' and 'p'. Fixes #587, fixes #690. --- src/pgsql/pgsql-schema.lisp | 9 +++++---- src/pgsql/sql/list-all-columns.sql | 2 +- src/pgsql/sql/list-all-fkeys.sql | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pgsql/pgsql-schema.lisp b/src/pgsql/pgsql-schema.lisp index 8a6f3ad..0b11653 100644 --- a/src/pgsql/pgsql-schema.lisp +++ b/src/pgsql/pgsql-schema.lisp @@ -108,10 +108,11 @@ :single))) -(defvar *table-type* '((:table . "r") - (:view . "v") - (:index . "i") - (:sequence . "S")) +(defvar *table-type* + '((:table . ("r" "f" "p")) ; ordinary, foreign and partitioned + (:view . ("v")) + (:index . ("i")) + (:sequence . ("S"))) "Associate internal table type symbol with what's found in PostgreSQL pg_class.relkind column.") diff --git a/src/pgsql/sql/list-all-columns.sql b/src/pgsql/sql/list-all-columns.sql index ce3b634..d3223e1 100644 --- a/src/pgsql/sql/list-all-columns.sql +++ b/src/pgsql/sql/list-all-columns.sql @@ -16,7 +16,7 @@ and a.attnum = def.adnum where nspname !~~ '^pg_' and n.nspname <> 'information_schema' - and relkind = '~a' + and relkind in (~{'~a'~^, ~}) ~:[~*~;and (~{~a~^~&~10t or ~})~] ~:[~*~;and (~{~a~^~&~10t and ~})~] diff --git a/src/pgsql/sql/list-all-fkeys.sql b/src/pgsql/sql/list-all-fkeys.sql index cd53ab1..8ebe8b5 100644 --- a/src/pgsql/sql/list-all-fkeys.sql +++ b/src/pgsql/sql/list-all-fkeys.sql @@ -27,7 +27,8 @@ JOIN pg_class cf on r.confrelid = cf.oid JOIN pg_namespace nf on cf.relnamespace = nf.oid where r.contype = 'f' - AND c.relkind = 'r' and cf.relkind = 'r' + AND c.relkind in ('r', 'f', 'p') + AND cf.relkind in ('r', 'f', 'p') AND n.nspname !~~ '^pg_' and n.nspname <> 'information_schema' AND nf.nspname !~~ '^pg_' and nf.nspname <> 'information_schema' ~:[~*~;and (~{~a~^~&~10t or ~})~]