Re: [Fwd: Names of columns used by primary key]
am 16.08.2002 17:08:05 von Dan Wilson
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 :
> 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.
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
[Fwd: Names of columns used by primary key]
am 16.08.2002 20:32:33 von Kevin Gordon
This is a multi-part message in MIME format.
--------------020505040409020002090804
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
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.
--------------020505040409020002090804
Content-Type: message/rfc822;
name="Names of columns used by primary key"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Names of columns used by primary key"
X-Mozilla-Status2: 00800000
Message-ID: <3D5C83C2.2000903@paradise.net.nz>
Date: Fri, 16 Aug 2002 16:46:58 +1200
From: Kevin Gordon
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020616
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-php-owner@postgresql.org
Subject: Names of columns used by primary key
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Question for pqsql-php mail list:
How can I determine the names of the columns that make up the primary key?
Your help would be appreciated.
--------------020505040409020002090804
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
--------------020505040409020002090804--
Re: [Fwd: Names of columns used by primary key]
am 17.08.2002 01:08:19 von Keary Suska
on 8/16/02 12:32 PM, kgordon@paradise.net.nz purportedly said:
> 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.
What you need is found in the system catalogs.
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org