Re: derive the sequence name of a column

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: derive the sequence name of a column
Дата
Msg-id 20031030070912.O39861@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Re: derive the sequence name of a column  ("Mel Jamero" <mel@gmanmi.tv>)
Ответы Re: derive the sequence name of a column  ("Mel Jamero" <mel@gmanmi.tv>)
Список pgsql-novice
On Thu, 30 Oct 2003, Mel Jamero wrote:

> Thank for the reply Bruno but I need more. =)
>
> Sorry, I have to send this again because I haven't figured out how to
> solve this.
>
> Can anyone please tell me exactly how the name of a sequence a field is
> using (manually created or generated by a serial) could be derived
> programmatically (using libpq or through SQL)?
>
> Thus:
>
> CREATE SEQUENCE an_unknown_sequence_name;
> CREATE TABLE test (
>   test_id   integer default nextval('an_unknown_sequence_name'),
>   useless_redundant_test_id serial
> );
>
> How do I programmatically extract that column 'test_id' in table 'test'
> is using 'an_unknown_sequence_name'

I'd suggest looking in pg_attrdef.

Something like:

select pg_attrdef.* from pg_attrdef, pg_namespace, pg_class, pg_attribute
where pg_namespace.nspname='public' and
pg_class.relnamespace=pg_namespace.oid and pg_class.relname='test' and
pg_attribute.attrelid=pg_class.oid and pg_attribute.attname='test_id' and
pg_attrdef.adrelid=pg_class.oid and pg_attrdef.adnum=pg_attribute.attnum;

(filling in the schema, table name and column name for the constants).


В списке pgsql-novice по дате отправления:

Предыдущее
От: Ennio-Sr
Дата:
Сообщение: [OT] Unable to access PostgreSQL mailing list archive
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [OT] Unable to access PostgreSQL mailing list archive