Re: Enforce primary key on every table during dev?

Поиск
Список
Период
Сортировка
От Tim Cross
Тема Re: Enforce primary key on every table during dev?
Дата
Msg-id 87vaegq0v4.fsf@gmail.com
обсуждение исходный текст
Ответ на Enforce primary key on every table during dev?  (Jeremy Finzel <finzelj@gmail.com>)
Ответы Re: Enforce primary key on every table during dev?
Re: Enforce primary key on every table during dev?
Список pgsql-general
Jeremy Finzel <finzelj@gmail.com> writes:

> We want to enforce a policy, partly just to protect those who might forget,
> for every table in a particular schema to have a primary key.  This can't
> be done with event triggers as far as I can see, because it is quite
> legitimate to do:
>
> BEGIN;
> CREATE TABLE foo (id int);
> ALTER TABLE foo ADD PRIMARY KEY (id);
> COMMIT;
>
> It would be nice to have some kind of "deferrable event trigger" or some
> way to enforce that no transaction commits which added a table without a
> primary key.
>

I think you would be better off having an automated report which alerts
you to tables lacking a primary key and deal with that policy through
other means. Using triggers in this way often leads to unexpected
behaviour and difficult to identify bugs. The policy is a management
policy and probably should be dealt with via management channels rather
than technical ones. Besides, the likely outcome will be your developers
will just adopt the practice of adding a serial column to every table,
which in itself doesn't really add any value.

Tim


-- 
Tim Cross


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

Предыдущее
От: Charles Clavadetscher
Дата:
Сообщение: Re: How to avoid trailing zero (after decimal point) for numeric type column
Следующее
От: chris
Дата:
Сообщение: Re: selecting timestamp