pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Adding custom constraints on a postgres database
3+ messages / 3 participants
[nested] [flat]

* Adding custom constraints on a postgres database
@ 2024-02-29 18:09  Debraj Manna <subharaj.manna@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Debraj Manna @ 2024-02-29 18:09 UTC (permalink / raw)
  To: pgsql-admin

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.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Adding custom constraints on a postgres database
@ 2024-02-29 18:26  David G. Johnston <david.g.johnston@gmail.com>
  parent: Debraj Manna <subharaj.manna@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: David G. Johnston @ 2024-02-29 18:26 UTC (permalink / raw)
  To: Debraj Manna <subharaj.manna@gmail.com>; +Cc: pgsql-admin

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

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Adding custom constraints on a postgres database
@ 2024-02-29 18:35  Tom Lane <tgl@sss.pgh.pa.us>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2024-02-29 18:35 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Debraj Manna <subharaj.manna@gmail.com>; pgsql-admin

"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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2024-02-29 18:35 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 18:09 Adding custom constraints on a postgres database Debraj Manna <subharaj.manna@gmail.com>
2024-02-29 18:26 ` David G. Johnston <david.g.johnston@gmail.com>
2024-02-29 18:35   ` Tom Lane <tgl@sss.pgh.pa.us>

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