Thread: deduce sequence name from table and column

deduce sequence name from table and column

From
Louis-David Mitterrand
Date:
Hi,

Is there a way (from DBI) to deduce a sequence name from the table and
column it is attached to?

For instance:

  Column    |  Type   |                                Modifiers
-------------+---------+--------------------------------------------------------------------------
 id_fonction | integer | not null default nextval(('"fonction_id_fonction_seq"'::text)::regclass)

I'd like to be able to programmatically find "fonction_id_fonction_seq"
so that I can then call nextval() on it.

Thanks,

--
Only half the people in the world are above average intelligence.

Re: deduce sequence name from table and column

From
Tom Lane
Date:
Louis-David Mitterrand <vindex@apartia.org> writes:
> Is there a way (from DBI) to deduce a sequence name from the table and
> column it is attached to?

Since 8.0 you can use pg_get_serial_sequence(), see
http://www.postgresql.org/docs/8.0/static/functions-info.html

            regards, tom lane

Re: deduce sequence name from table and column

From
Louis-David Mitterrand
Date:
On Tue, Dec 20, 2005 at 10:31:46AM -0500, Tom Lane wrote:
> Louis-David Mitterrand <vindex@apartia.org> writes:
> > Is there a way (from DBI) to deduce a sequence name from the table and
> > column it is attached to?
>
> Since 8.0 you can use pg_get_serial_sequence(), see
> http://www.postgresql.org/docs/8.0/static/functions-info.html

Just what I needed,
Thanks!

--
                      -= this .sig is not funny =-