From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Debraj Manna <subharaj.manna@gmail.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Adding custom constraints on a postgres database
Date: Thu, 29 Feb 2024 13:35:25 -0500
Message-ID: <2720842.1709231725@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYej5N-T-6YADf1ZLKAKcQ1Avd7xHozTpcG5g8zY1tNeg@mail.gmail.com>
References: <CAF6DVKMxbfsuK65SgrNdoBnhWdmx86Sku+Th1e5-QQWx_oncRg@mail.gmail.com>
<CAKFQuwYej5N-T-6YADf1ZLKAKcQ1Avd7xHozTpcG5g8zY1tNeg@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thu, Feb 29, 2024, 11:10 Debraj Manna <subharaj.manna@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, subharaj.manna@gmail.com
Subject: Re: Adding custom constraints on a postgres database
In-Reply-To: <2720842.1709231725@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox