Re: [Fwd: Names of columns used by primary key]

Поиск
Список
Период
Сортировка
От Dan Wilson
Тема Re: [Fwd: Names of columns used by primary key]
Дата
Msg-id 1029510485.3d5d15554800f@webmail.acucore.com
обсуждение исходный текст
Ответ на [Fwd: Names of columns used by primary key]  (Kevin Gordon <kgordon@paradise.net.nz>)
Список pgsql-php
This query should help you out:

SELECT
    ic.relname AS index_name,
    bc.relname AS tab_name,
    ta.attname AS column_name,
    i.indisunique AS unique_key,
    i.indisprimary AS primary_key
FROM
    pg_class bc,
    pg_class ic,
    pg_index i,
    pg_attribute ta,
    pg_attribute ia
WHERE
    bc.oid = i.indrelid
    AND ic.oid = i.indexrelid
    AND ia.attrelid = i.indexrelid
    AND ta.attrelid = bc.oid
    AND bc.relname = '[table_name]'
    AND ta.attrelid = i.indrelid
    AND ta.attnum = i.indkey[ia.attnum-1]
ORDER BY
    index_name, tab_name, column_name

Of course, be sure to change the "[table_name]".  Then all you have to do is
check if primary_key is 't' and then get the column name.

-Dan

Quoting Kevin Gordon <kgordon@paradise.net.nz>:

> Question for pqsql-php mail list:
> How can I determine the names of the columns that make up the primary
> key in a postgresql table?
> Your help would be appreciated.

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

Предыдущее
От: "Brian Moon"
Дата:
Сообщение: PostgreSQL guru needed for Phorum.
Следующее
От: "Brian Moon"
Дата:
Сообщение: Re: [GENERAL] PostgreSQL with Phorum