Skip site navigation (1) Skip section navigation (2)

Re: Getting name of sequence for a table

From: Dave Page <dpage(at)vale-housing(dot)co(dot)uk>
To: 'Nicolas Ribot' <nicolas(dot)ribot(at)scot(dot)cnes(dot)fr>,pgadmin-hackers(at)postgresql(dot)org
Subject: Re: Getting name of sequence for a table
Date: 2002-03-17 20:28:40
Message-ID: FED2B709E3270E4B903EB0175A49BCB10476B8@dogbert.vale-housing.co.uk (view raw or flat)
Thread:
Lists: pgadmin-hackers

> -----Original Message-----
> From: Nicolas Ribot [mailto:nicolas(dot)ribot(at)scot(dot)cnes(dot)fr] 
> Sent: 15 March 2002 09:19
> To: pgadmin-hackers(at)postgresql(dot)org
> Subject: [pgadmin-hackers] Getting name of sequence for a table
> 
> 
> Hello,
> 
> I was wondering if it is possible to get the name of 
> sequences created for a table by an SQL query ?
> 
> Ex: I have a parcel table, with a sequence created on it for 
> the PK column. A java program, that doesn't know this 
> sequence name needs  to retrieve the unique ID of the object 
> recently inserted into the parcel table. I would like to do 
> something like select currval( (select seqname from pg_xxx 
> where table_name='parcel') ).
> 
> I looked at the pg_class system table and see both my table 
> and its sequence, but do not find a way to join them in a query.

This is way off-topic for this list, but:

pg_attrdef.adrelid = the oid of your table
pg_attrdef.adnum = the column number you're interested in
pg_attrdef.adsrc = nextval('seq_name'::text)

For further help, checkout the catalog diagrams in the developers guide, and
try a PostgreSQL support list.

Regards, Dave.

pgadmin-hackers by date

Next:From: Tim FinchDate: 2002-03-18 18:09:44
Subject: TCL in WinCVS
Previous:From: Dave PageDate: 2002-03-17 19:57:53
Subject: Re: upgrade wizard proxy connection

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group