Re: Querying database for table pk - better way?

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Josh Trutwin" <josh(at)trutwins(dot)homeip(dot)net>
Cc: "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Querying database for table pk - better way?
Date: 2007-09-05 23:08:33
Message-ID: b42b73150709051608s49080187s96e4816a1c56ecf1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 9/5/07, Josh Trutwin <josh(at)trutwins(dot)homeip(dot)net> wrote:
> I have a php application that needs to query the PK of a table - I'm
> currently using this from the information_schema views:

try this:
CREATE OR REPLACE VIEW PKEYS AS
SELECT nspname as schema, c2.oid as tableoid, c2.relname as table,
substring(pg_catalog.pg_get_indexdef(i.indexrelid, 0, true) from
E'\\((.*)\\)')
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2,
pg_catalog.pg_index i, pg_namespace n
WHERE c.oid = i.indrelid AND i.indexrelid = c2.oid AND c.relkind = 'r'
AND i.indisprimary AND c.relnamespace = n.oid
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname;

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message A.M. 2007-09-05 23:13:51 Re: pg_dump doesn't dump everything?
Previous Message Liam Slusser 2007-09-05 22:57:32 pg_dump doesn¹t dump everything?