On Sat, 2003-08-02 at 17:19, Carlos Guzman Alvarez wrote:
> Hello:
>
> I continue to be working in my .NET Data provider for postgres 7.4, i
> want to know if there are a simple way for identify autoincrement
> fields, i see that for serial and big serial fields the default value is
> 'nextval(...)' this can be a way for know it but i want to know if there
> are a better way :)
In SERIAL columns the sequence depends on the column, so the association
can be gathered from pg_depend.
Check for a relation between a sequence and column of a table where the
deptype = 'i'. (Taken from pg_dump)
SELECT c.oid, relname, relacl, relkind,
relnamespace,
(select usename from pg_user where relowner = usesysid) as usename,
relchecks, reltriggers,
relhasindex, relhasrules, relhasoids,
d.refobjid as owning_tab,
d.refobjsubid as owning_col
from pg_class c
join pg_depend d on (c.relkind = 'S' and d.classid = c.tableoid and d.objid = c.oid and d.objsubid = 0 and
d.refclassid= c.tableoid and d.deptype = 'i')
where relkind in ('t', 'S', 'v')
order by c.oid
;