sequences and dependences

Started by Laurent ROCHEalmost 18 years ago3 messagesgeneral
Jump to latest
#1Laurent ROCHE
laurent_roche@yahoo.com

Hi,

I would like to write a request where I would get the table name and column name of a sequence.
In fact I want the opposite of pg_get_serial_sequence !

I have been looking at the sytem table and could not link the sequence from pg_class to a table (and even less to a table).
And I have not been sucessful looking at the net either !

Cheers,
L@u
The Computing Froggy

__________________________________________________
Do You Yahoo!?
En finir avec le spam? Yahoo! Mail vous offre la meilleure protection possible contre les messages non sollicités
http://mail.yahoo.fr Yahoo! Mail

#2Ioannis Tambouras
ioannis@akroninc.net
In reply to: Laurent ROCHE (#1)
Re: sequences and dependences

I would like to write a request where I would get the table name and
column name of a sequence.
In fact I want the opposite of pg_get_serial_sequence !

You are looking for refobjid in pg_depend, but this
time the sequence could be a dependent to more than table.

A query like the one bellow is should give you the name of the table,
assuming you account for the correct namespace; it will not automatically
show the name of the column:

select objid::regclass, refobjid::regclass
from pg_depend
where objid::regclass::text = 'person_id_seq' ;

Thanks
Ioannis Tambouras

#3Greg Smith
gsmith@gregsmith.com
In reply to: Laurent ROCHE (#1)
Re: sequences and dependences

On Fri, 23 May 2008, Laurent ROCHE wrote:

I would like to write a request where I would get the table name and
column name of a sequence. I have been looking at the sytem table and
could not link the sequence from pg_class to a table (and even less to a
table).

There's an example of how to chain between two pg_class entries using
pg_depend that I think is close to what you're looking for at
http://wiki.postgresql.org/wiki/Fixing_Sequences

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD