pg_get_serial_sequence and table inheritence

Поиск
Список
Период
Сортировка
Искать

pg_get_serial_sequence and table inheritence

От:
Timothy Perrigo <tperrigo@wernervas.com>
Дата:
Is there anything similar to pg_get_serial_sequence that will work  
with tables that have an inherited serial column?  For example, if I  
have 2 tables:

create table base (
id    serial not null primary key
);

and

create table derived (
stuff    text,
constraint derived_pkey primary key(id)
) inherits (base);

I'd like to be able to call pg_get_serial_sequence passing "derived"  
for the table and "id" for the sequence column (to get, in this case  
"base_id_seq").  If nothing like this currently exists, any  
suggestions on how I could write a plpgsql function to get this  
behavior?

Thank you for any suggestions!
Tim


Re: pg_get_serial_sequence and table inheritence

От:
Rafa Couto <rafacouto@gmail.com>
Дата:
2005/5/31, Timothy Perrigo :

> I'd like to be able to call pg_get_serial_sequence passing "derived"
> for the table and "id" for the sequence column (to get, in this case
> "base_id_seq").  If nothing like this currently exists, any
> suggestions on how I could write a plpgsql function to get this
> behavior?

  You have one sequence for every serial field in sequences (from psql: "\ds").
  

-- 
Rafa Couto (caligari)
mailto:rafacouto@gmail.com

Re: pg_get_serial_sequence and table inheritence

От:
Ezequiel Tolnay <mail@etolnay.com.ar>
Дата:
Timothy Perrigo wrote:

> Is there anything similar to pg_get_serial_sequence that will work  with 
> tables that have an inherited serial column?  (...)

Sorry, I should have searched before posting, I started a new thread. 
Please refer to my solution posted today as "pg_get_serial_sequence and 
inheritence" (remarkably similar to yours! although mine was less 
accurate ;-)

Cheers,

Ezequiel
FAQ