Re: Getting the currently used sequence for a SERIAL column - Mailing list pgsql-general

From Hanne Moa
Subject Re: Getting the currently used sequence for a SERIAL column
Date
Msg-id 65ff537f-9ac5-1974-0d1c-aba9f2b770c4@gmail.com
Whole thread Raw
In response to Re: Getting the currently used sequence for a SERIAL column  (Thomas Kellerer <spam_eater@gmx.net>)
Responses Re: Getting the currently used sequence for a SERIAL column  (Thomas Kellerer <spam_eater@gmx.net>)
List pgsql-general
On 2016-10-19 09:28, Thomas Kellerer wrote:
> You can use the following statement to find the sequences that a table uses:
>
>     select sn.nspname as sequence_schema, s.relname as sequence_name
>     from pg_class s
>       join pg_namespace sn on sn.oid = s.relnamespace
>       join pg_depend d on d.refobjid = s.oid and d.refclassid='pg_class'::regclass
>       join pg_attrdef ad on ad.oid = d.objid and d.classid = 'pg_attrdef'::regclass
>       join pg_attribute col on col.attrelid = ad.adrelid and col.attnum = ad.adnum
>       join pg_class tbl on tbl.oid = ad.adrelid
>       join pg_namespace n on n.oid = tbl.relnamespace
>     where s.relkind = 'S'
>       and d.deptype in ('a', 'n')
>       and n.nspname = 'public'
>       and tbl.relname = 'foo'

Thanks. This assumes that there is only one nextval per table though.
While this holds for the database we need this on right now, it's not a
sufficiently generic solution. How do I, for the sake of paranoia,
specify a column?

Btw, is there a site with recipes showing what's possible to do with the
pg_*-tables?



HM


pgsql-general by date:

Previous
From: "t.dalpozzo@gmail.com"
Date:
Subject: Re: journaled FS and and WAL
Next
From: Thomas Kellerer
Date:
Subject: Re: Getting the currently used sequence for a SERIAL column