Re: primary keys

From: ptjm(at)interlog(dot)com (Patrick TJ McPhee)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: primary keys
Date: 2006-04-20 04:19:51
Message-ID: 4aogf6Fu7u5lU1@uni-berlin.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <4447021E23B(dot)9BA8KG(at)129(dot)180(dot)47(dot)120>,
Klint Gore <kg(at)kgb(dot)une(dot)edu(dot)au> wrote:

% works for me on version 8.1.3
%
% SELECT attname
% FROM pg_index
% JOIN pg_class ON (indrelid = pg_class.oid)
% JOIN pg_attribute ON (attrelid = pg_class.oid)
% WHERE indisprimary IS TRUE
% AND attnum = any(indkey)
% AND relname = $tablename;

This will work on 7.4, 8.0, or 8.1

SELECT attname
FROM pg_index
JOIN pg_class as c1 ON (indrelid = c1.oid)
JOIN pg_class as c2 ON (indexrelid = c2.oid)
JOIN pg_attribute ON (attrelid = c2.oid)
WHERE indisprimary
AND c1.relname = $tablename
;

No arrays are hurt by this query.
--

Patrick TJ McPhee
North York Canada
ptjm(at)interlog(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message surabhi.ahuja 2006-04-20 06:31:58 FW: code to cancel a running query, worker thread
Previous Message Harvey, Allan AC 2006-04-20 03:56:04 Re: deleting table content through command prompt