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.
This commit is contained in:
Dimitri Fontaine 2020-02-11 21:46:10 +01:00
parent 26cc9ca79f
commit 8a13c02561

View File

@ -7,8 +7,8 @@ with seqattr as
( (
select adrelid, select adrelid,
adnum, adnum,
adsrc, pg_get_expr(d.adbin, d.adrelid) as adsrc,
case when adsrc ~~ 'nextval' case when pg_get_expr(d.adbin, d.adrelid) ~~ 'nextval'
then substring(pg_get_expr(d.adbin, d.adrelid) then substring(pg_get_expr(d.adbin, d.adrelid)
from '''([^'']+)''' from '''([^'']+)'''
) )
@ -23,7 +23,9 @@ with seqattr as
else null else null
end as typmod, end as typmod,
attnotnull, 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 case when s.seqname is not null then 'auto_increment' end as extra
from pg_class c from pg_class c
join pg_namespace n on n.oid = c.relnamespace join pg_namespace n on n.oid = c.relnamespace