Re: CHECK Constraint Deferrable - Mailing list pgsql-hackers

From Andreas Joseph Krogh
Subject Re: CHECK Constraint Deferrable
Date
Msg-id VisenaEmail.61b.53e58ccb717c3e7c.18af2d80969@origo02.app.internal.visena.net
Whole thread Raw
In response to Re: CHECK Constraint Deferrable  (Dilip Kumar <dilipbalaut@gmail.com>)
Responses Re: CHECK Constraint Deferrable
List pgsql-hackers
På fredag 07. juli 2023 kl. 13:50:44, skrev Dilip Kumar <dilipbalaut@gmail.com>:
On Wed, Jul 5, 2023 at 3:08 PM Himanshu Upadhyaya
<upadhyaya.himanshu@gmail.com> wrote:
>
> Hi,
>
> Currently, there is no support for CHECK constraint DEFERRABLE in a create table statement.
> SQL standard specifies that CHECK constraint can be defined as DEFERRABLE.

I think this is a valid argument that this is part of SQL standard so
it would be good addition to PostgreSQL.  So +1 for the feature.

But I am wondering whether there are some real-world use cases for
deferred CHECK/NOT NULL constraints?  I mean like for foreign key
constraints if there is a cyclic dependency between two tables then
deferring the constraint is the simplest way to insert without error.

 

The real-world use case, at least for me, is when using an ORM. For large object-graphs ORMs have a tendency to INSERT first with NULLs then UPDATE the “NOT NULLs” later.

“Rewrite the ORM” is not an option for most of us…

 

--

Andreas Joseph Krogh

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Replace (stat())[7] in TAP tests with -s
Next
From: Tom Lane
Date:
Subject: Re: CHECK Constraint Deferrable