From: Oliver Elphick <olly@lfix.co.uk>
To: "D'Arcy" "J.M." Cain <darcy@druid.net>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [HACKERS] Re: [SQL] SQL-Query 2 get primary key
Date: Sat, 20 Feb 1999 08:32:39 +0000
Message-ID: <199902200832.IAA09157@linda.lfix.co.uk> (raw)
In-Reply-To: <darcy@druid.net> <m10E4Vi-0000boC@druid.net>
"D'Arcy" "J.M." Cain wrote:
>Thus spake Marc Grimme
>> if I create a table like this:
>> CREATE TABLE test (
>> id decimal(3) primary key,
>> name varchar(32));
>>
>> how can I ask postgres which is the primary key from table test?
>
>SELECT pg_class.relname, pg_attribute.attname
> FROM pg_class, pg_attribute, pg_index
> WHERE pg_class.oid = pg_attribute.attrelid AND
> pg_class.oid = pg_index.indrelid AND
> pg_index.indkey[0] = pg_attribute.attnum AND
> pg_index.indisprimary = 't';
>
>That lists all the primary keys in your database. Add a "WHERE pg_class
>= 'test'" clause to get the specific table.
I tried this and got 0 rows. Every value of pg_index.indisprimary is
false, although I have nearly 100 tables created with primary keys.
(This is with 6.4.2)
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP key from public servers; key ID 32B8FAA1
========================================
"For the Lord himself shall descend from heaven with a
shout, with the voice of the archangel, and with the
trump of God; and the dead in Christ shall rise first;
Then we which are alive and remain shall be caught up
together with them in the clouds, to meet the Lord in
the air; and so shall we ever be with the Lord."
I Thessalonians 4:16,17
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: olly@lfix.co.uk, darcy@druid.net
Subject: Re: [HACKERS] Re: [SQL] SQL-Query 2 get primary key
In-Reply-To: <199902200832.IAA09157@linda.lfix.co.uk>
References: <199902200832.IAA09157@linda.lfix.co.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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