pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: [Fwd: Names of columns used by primary key]
1+ messages / 1 participants
[nested] [flat]
* Re: [Fwd: Names of columns used by primary key]
@ 2002-08-16 15:08 Dan Wilson <killroyboy@users.sourceforge.net>
0 siblings, 0 replies; 1+ messages in thread
From: Dan Wilson @ 2002-08-16 15:08 UTC (permalink / raw)
To: Kevin Gordon <kgordon@paradise.net.nz>; +Cc: 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.
^ permalink raw reply [nested|flat] 1+ messages in thread
only message in thread
Thread overview: 1+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-08-16 15:08 Re: [Fwd: Names of columns used by primary key] Dan Wilson <killroyboy@users.sourceforge.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox