From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | Debraj Manna <subharaj(dot)manna(at)gmail(dot)com>, pgsql-admin <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: Adding custom constraints on a postgres database |
Date: | 2024-02-29 18:35:25 |
Message-ID: | 2720842.1709231725@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Thu, Feb 29, 2024, 11:10 Debraj Manna <subharaj(dot)manna(at)gmail(dot)com> wrote:
>> Can someone let me know if there is a way I can add some custom
>> rules/constraints on a Postgres database?
>>
>> For example, all tables in a database should have a primary key specified.
>> If someone is trying to violate the rules specified then the SQL command
>> should fail.
> https://www.postgresql.org/docs/current/event-trigger-definition.html
When/where are you expecting to enforce this? If you prohibit the
common pattern of CREATE TABLE followed sometime later by ALTER TABLE
ADD PRIMARY KEY, you will soon regret that.
I think you might be better served by writing a lint-like thing
that can be run periodically to look through the system catalogs
for policy violations. Rejecting SQL commands on-the-fly will be
expensive, as well as painful to work with.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Domen Šetar | 2024-03-01 09:28:09 | Logical replication from standby |
Previous Message | David G. Johnston | 2024-02-29 18:26:27 | Re: Adding custom constraints on a postgres database |