Re: primary keys - Mailing list pgsql-general

From ptjm@interlog.com (Patrick TJ McPhee)
Subject Re: primary keys
Date
Msg-id 4aogf6Fu7u5lU1@uni-berlin.de
Whole thread Raw
In response to primary keys  (Orion Henry <lab@orangekids.org>)
List pgsql-general
In article <4447021E23B.9BA8KG@129.180.47.120>,
Klint Gore <kg@kgb.une.edu.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@interlog.com

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: psql: FATAL: missing or erroneous pg_hba.conf file
Next
From: "Mavinakuli, Prasanna (STSD)"
Date:
Subject: Re: HUGE Stack space is gettiing consumed