dvarrazzo / pg_seldump

PostgreSQL selective data dump
Other
13 stars 3 forks source link

automatically dump sequence if data is dump off a table depending on it #5

Closed dvarrazzo closed 4 years ago

dvarrazzo commented 4 years ago

check if you can find tables depending on sequences even if the sequence is owned by another table (two tables may use the same sequence, so we want to store its state as soon as either use it; the sequence can be owned by a single table)

dvarrazzo commented 4 years ago

This query returns the table attributes querying a sequence and the sequence depending on them

select tblns.nspname as table_schema, tbl.relname as table_name, att.attname as column,
    seqns.nspname as sequence_schema, seq.relname as sequence_name
from pg_depend dep
join pg_attrdef def on dep.classid = 'pg_attrdef'::regclass and dep.objid = def.oid
join pg_attribute att on (def.adrelid, def.adnum) = (att.attrelid, att.attnum)
join pg_class tbl on tbl.oid = att.attrelid
join pg_namespace tblns on tblns.oid = tbl.relnamespace
join pg_class seq on dep.refclassid = 'pg_class'::regclass and seq.oid = dep.refobjid and seq.relkind = 'S'
join pg_namespace seqns on seqns.oid = seq.relnamespace 
dvarrazzo commented 4 years ago

Implemented in 0.2