From: | Dan Wilson <killroyboy(at)users(dot)sourceforge(dot)net> |
---|---|
To: | Kevin Gordon <kgordon(at)paradise(dot)net(dot)nz> |
Cc: | pgsql-php(at)postgresql(dot)org |
Subject: | Re: [Fwd: Names of columns used by primary key] |
Date: | 2002-08-16 15:08:05 |
Message-ID: | 1029510485.3d5d15554800f@webmail.acucore.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)paradise(dot)net(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Mario Henley Becerril Geldis | 2002-08-16 17:39:52 | Timesheet |
Previous Message | Brian Moon | 2002-08-16 04:37:09 | PostgreSQL guru needed for Phorum. |