From 8a13c02561fe030301045f9f50d94f523dd61b2c Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 11 Feb 2020 21:46:10 +0100 Subject: [PATCH] Review our Postgres catalog usage for default values. The pg_catalog.pg_attribute column adsrc is populated only once, and then not maintained by the server. The function pg_get_expr(adbin, adrelid) is what to use and has been here since release 8.0, so that's what pgloader should be using. Fixed #1934. --- src/pgsql/sql/list-all-columns.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pgsql/sql/list-all-columns.sql b/src/pgsql/sql/list-all-columns.sql index 75f8a52..c9ce7ea 100644 --- a/src/pgsql/sql/list-all-columns.sql +++ b/src/pgsql/sql/list-all-columns.sql @@ -7,8 +7,8 @@ with seqattr as ( select adrelid, adnum, - adsrc, - case when adsrc ~~ 'nextval' + pg_get_expr(d.adbin, d.adrelid) as adsrc, + case when pg_get_expr(d.adbin, d.adrelid) ~~ 'nextval' then substring(pg_get_expr(d.adbin, d.adrelid) from '''([^'']+)''' ) @@ -23,7 +23,9 @@ with seqattr as else null end as typmod, attnotnull, - case when atthasdef then def.adsrc end as default, + case when atthasdef + then pg_get_expr(def.adbin, def.adrelid) + end as default , case when s.seqname is not null then 'auto_increment' end as extra from pg_class c join pg_namespace n on n.oid = c.relnamespace