From: Tom Lane <tgl@sss.pgh.pa.us>
To: Melvin Davidson <melvin6925@gmail.com>
Cc: pgsql-general@postgresql.org >> PG-General Mailing List <pgsql-general@postgresql.org>
Subject: Re: Restore relhaspkey in PostgreSQL Version 11 Beta
Date: Mon, 30 Jul 2018 10:31:01 -0400
Message-ID: <27216.1532961061@sss.pgh.pa.us> (raw)
In-Reply-To: <CANu8Fiy2RZL+uVnnrzaCTJxMgcKBDOnAR7bDx3n0P=KycbSNhA@mail.gmail.com>
References: <CANu8Fiy2RZL+uVnnrzaCTJxMgcKBDOnAR7bDx3n0P=KycbSNhA@mail.gmail.com>
Melvin Davidson <melvin6925@gmail.com> writes:
> In the release notes for Version 11 Beta, under changes, I see these scary
> remarks:
> Remove relhaspkey column from system table pg_class (Peter Eisentraut)
> Applications needing to check for a primary key should consult pg_index.
>
> That absolutely breaks my code (and I'm guessing others), as I have a cron
> job that checks for tables that were created with no pkey.
Well, I'd say your code was broken anyway, because it has never been the
case that relhaspkey meant that the table *currently* has a primary key.
We got rid of it on the grounds that its semantics were too squishy to
be useful.
What you want is something like
select relname from pg_class c where relkind = 'r' and
not exists (select 1 from pg_index where indrelid = c.oid and indisprimary);
which will give the right answer in all PG versions.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, melvin6925@gmail.com
Subject: Re: Restore relhaspkey in PostgreSQL Version 11 Beta
In-Reply-To: <27216.1532961061@sss.pgh.pa.us>
References: <CANu8Fiy2RZL+uVnnrzaCTJxMgcKBDOnAR7bDx3n0P=KycbSNhA@mail.gmail.com> <27216.1532961061@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox