| From: | Melvin Davidson <melvin6925(at)gmail(dot)com> |
|---|---|
| To: | Dustin Kempter <dustink(at)consistentstate(dot)com> |
| Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Primary Keys |
| Date: | 2016-04-29 18:20:21 |
| Message-ID: | CANu8FiyQsQg7bF3FPT+FU=kK=WJHfewPp+6qE9fxF6YXr+WNCA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Fri, Apr 29, 2016 at 2:07 PM, Dustin Kempter <dustink(at)consistentstate(dot)com
> wrote:
> Hi all,
> Is there a query I can run that will scan through all the tables of a
> database and give me a list of all tables without a primary key? Im not
> having any luck with this.
>
> Thanks in advance!
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
Please, ALWAYS provide Postgresql version & O/S, regardless of whether you
think it is pertinet.
Now try this:
SELECT n.nspname, c.relname as table
FROM pg_class c
JOIN pg_namespace n ON (n.oid =c.relnamespace )
WHERE relkind = 'r' AND
relname NOT LIKE 'pg_%' AND
relname NOT LIKE 'sql_%' AND
relhaspkey = FALSE
ORDER BY n.nspname, c.relname;
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | John McKown | 2016-04-29 18:27:34 | Re: Primary Keys |
| Previous Message | John R Pierce | 2016-04-29 18:09:50 | Re: Postgres processes getting stuck (bug?) |