Re: Identification of serial fields

From: Rod Taylor <rbt(at)rbt(dot)ca>
To: Carlos Guzman Alvarez <carlosga(at)telefonica(dot)net>
Cc: Developement <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Identification of serial fields
Date: 2003-08-02 21:39:24
Message-ID: 1059860363.43336.139.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
;

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Carlos Guzman Alvarez 2003-08-02 22:20:51 Re: Identification of serial fields
Previous Message Jenny - 2003-08-02 21:27:51 locking granularity