From: | David Fetter <david(at)fetter(dot)org> |
---|---|
To: | SF Postgres <sfpug(at)postgresql(dot)org> |
Subject: | Re: listing all tables without primary key |
Date: | 2005-05-17 01:05:55 |
Message-ID: | 20050517010555.GG22770@fetter.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | sfpug |
On Mon, May 16, 2005 at 05:43:58PM -0700, Jeff Frost wrote:
> Is there a simple way to list all tables without a primary key? Googling
> on this subject has not turned up any helpful sources thus far.
Here's what I've come up with:
SELECT
n.nspname AS "Schema",
c.relname AS "Table Name",
c.relhaspkey AS "Has PK"
FROM
pg_catalog.pg_class c
JOIN
pg_namespace n
ON (
c.relnamespace = n.oid
AND n.nspname NOT IN ('information_schema', 'pg_catalog')
AND c.relkind='r'
)
ORDER BY c.relhaspkey, c.relname
;
How would this work in the new system views?
Cheers,
D
--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778
Remember to vote!
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2005-05-17 01:08:31 | Re: listing all tables without primary key |
Previous Message | Jeff Frost | 2005-05-17 00:43:58 | listing all tables without primary key |