Re: Restore relhaspkey in PostgreSQL Version 11 Beta

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Restore relhaspkey in PostgreSQL Version 11 Beta
Дата
Msg-id 27216.1532961061@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Restore relhaspkey in PostgreSQL Version 11 Beta  (Melvin Davidson <melvin6925@gmail.com>)
Ответы Re: Restore relhaspkey in PostgreSQL Version 11 Beta  (Melvin Davidson <melvin6925@gmail.com>)
Список pgsql-general
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


В списке pgsql-general по дате отправления:

Предыдущее
От: Melvin Davidson
Дата:
Сообщение: Restore relhaspkey in PostgreSQL Version 11 Beta
Следующее
От: hmidi slim
Дата:
Сообщение: Design of a database table