Re: Identification of serial fields - Mailing list pgsql-hackers

From Rod Taylor
Subject Re: Identification of serial fields
Date
Msg-id 1059860363.43336.139.camel@jester
Whole thread Raw
In response to Identification of serial fields  (Carlos Guzman Alvarez <carlosga@telefonica.net>)
Responses Re: Identification of serial fields
List pgsql-hackers
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
;




pgsql-hackers by date:

Previous
From: "Jenny -"
Date:
Subject: locking granularity
Next
From: Carlos Guzman Alvarez
Date:
Subject: Re: Identification of serial fields