Re: Dynamic constraint names in ALTER TABLE

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Dynamic constraint names in ALTER TABLE
Дата
Msg-id 201109191808.41283.adrian.klaver@gmail.com
обсуждение исходный текст
Ответ на Dynamic constraint names in ALTER TABLE  (patrick keshishian <pkeshish@gmail.com>)
Ответы Re: Dynamic constraint names in ALTER TABLE
Список pgsql-general
On Monday, September 19, 2011 5:10:45 pm patrick keshishian wrote:
> Hi,
>

>
>
> Is there any way the .sql scripts could make use of this query to get
> the foreign key name from pg_constraint table, regardless of PG
> version (7.4.x or 9.x)?

Use the information schema?  As example:
http://www.postgresql.org/docs/7.4/static/infoschema-table-constraints.html
http://www.postgresql.org/docs/9.0/interactive/infoschema-table-constraints.html

>
> foo=# SELECT conname FROM pg_constraint JOIN pg_class ON
> (conrelid=pg_class.oid) WHERE pg_class.relname='sales' AND conkey[1] =
> 1 AND contype='f';
>
> In PostgreSQL 7.4.17:
>  conname
> ---------
>  $1
> (1 row)
>
>
> In PostgreSQL 9.0.3:
>       conname
> -------------------
>  sales_seller_fkey
> (1 row)
>
>
> Thanks for reading,
> --patrick

--
Adrian Klaver
adrian.klaver@gmail.com

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

Предыдущее
От: patrick keshishian
Дата:
Сообщение: Dynamic constraint names in ALTER TABLE
Следующее
От: patrick keshishian
Дата:
Сообщение: Re: Dynamic constraint names in ALTER TABLE