Use (BIG)SERIAL in generated SQL when this was used when column

originally defined.

This is recognized by the fact that the column has a dependency on a
sequence. For columns that happen to have a default which uses a pre
exising sequence the dependency is the other way around.
This commit is contained in:
eelke 2019-12-01 06:40:11 +01:00
parent 817a371220
commit 2c2253f75e
3 changed files with 26 additions and 9 deletions

View file

@ -12,12 +12,15 @@ std::string PgAttributeContainer::getLoadQuery() const
std::string q = R"__(
SELECT attrelid, attname, atttypid, attstattarget,
attnum, attndims, atttypmod, attnotnull, atthasdef, attisdropped,
attislocal, attcollation, attacl, attoptions, pg_get_expr(adbin, adrelid) AS def_value)__";
attislocal, attcollation, attacl, attoptions, pg_get_expr(def.adbin, def.adrelid) AS def_value, cs.relname AS sername, ns.nspname AS serschema)__";
if (m_catalog.serverVersion() >= 100000)
q += ", attidentity";
q +=
"\n FROM pg_catalog.pg_attribute \n"
" LEFT JOIN pg_attrdef ON attrelid=adrelid AND attnum=adnum";
q += R"__(
FROM pg_catalog.pg_attribute AS att
LEFT JOIN pg_attrdef AS def ON attrelid=adrelid AND attnum=adnum
LEFT JOIN (pg_depend JOIN pg_class cs ON classid='pg_class'::regclass AND objid=cs.oid AND cs.relkind='S') ON refobjid=att.attrelid AND refobjsubid=att.attnum
LEFT JOIN pg_namespace ns ON ns.oid=cs.relnamespace)__";
return q;
}
@ -27,7 +30,8 @@ PgAttribute PgAttributeContainer::loadElem(const Pgsql::Row &row)
PgAttribute v;
col >> v.relid >> v.name >> v.typid >> v.stattarget
>> v.num >> v.ndims >> v.typmod >> v.notnull >> v.hasdef >> v.isdropped
>> v.islocal >> v.collation >> v.acl >> v.options >> v.defaultValue;
>> v.islocal >> v.collation >> v.acl >> v.options >> v.defaultValue
>> v.sername >> v.serschema;
if (m_catalog.serverVersion() >= 100000)
col >> v.identity;