Search Postgresql Archives

Re: Primary Keys

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

 





On Fri, Apr 29, 2016 at 2:07 PM, Dustin Kempter <dustink@xxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx)
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.


[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