Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fk9CZ-0006H2-RO for pgsql-general@arkaria.postgresql.org; Mon, 30 Jul 2018 14:31:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fk9CX-0006tL-Ot for pgsql-general@arkaria.postgresql.org; Mon, 30 Jul 2018 14:31:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fk9CX-0006tD-GU for pgsql-general@lists.postgresql.org; Mon, 30 Jul 2018 14:31:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fk9CU-0008Lw-IV for pgsql-general@postgresql.org; Mon, 30 Jul 2018 14:31:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w6UEV1TS027217; Mon, 30 Jul 2018 10:31:02 -0400 From: Tom Lane To: Melvin Davidson cc: "pgsql-general@postgresql.org >> PG-General Mailing List" Subject: Re: Restore relhaspkey in PostgreSQL Version 11 Beta In-reply-to: References: Comments: In-reply-to Melvin Davidson message dated "Mon, 30 Jul 2018 10:20:20 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27215.1532961061.1@sss.pgh.pa.us> Date: Mon, 30 Jul 2018 10:31:01 -0400 Message-ID: <27216.1532961061@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Melvin Davidson 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