Enforce primary key on every table during dev?

From: Jeremy Finzel <finzelj(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Enforce primary key on every table during dev?
Date: 2018-02-28 13:34:17
Message-ID: CAMa1XUie6LD140KdMY7cst41uCaa5B1YEgJ3GH3XSgDh2WXguQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

Any ideas?

Thanks,
Jeremy

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2018-02-28 13:46:41 Re: Enforce primary key on every table during dev?
Previous Message pkashimalla 2018-02-28 12:33:46 How to avoid trailing zero (after decimal point) for numeric type column