Search Postgresql Archives

Re: primary keys

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <4447021E23B.9BA8KG@xxxxxxxxxxxxxx>,
Klint Gore <kg@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxx


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux