Re: CHECK Constraint Deferrable

2023-10-12 Thread Vik Fearing
On 10/10/23 15:12, Robert Haas wrote: On Mon, Oct 9, 2023 at 5:07 PM David G. Johnston wrote: 2. I don't think it's a good idea for the same patch to try to solve two problems unless they are so closely related that solving one without solving the other is not sensible. A NOT NULL constraint

Re: CHECK Constraint Deferrable

2023-10-10 Thread Robert Haas
On Mon, Oct 9, 2023 at 5:07 PM David G. Johnston wrote: >> 2. I don't think it's a good idea for the same patch to try to solve >> two problems unless they are so closely related that solving one >> without solving the other is not sensible. > > A NOT NULL constraint apparently is just a special c

Re: CHECK Constraint Deferrable

2023-10-09 Thread David G. Johnston
On Mon, Oct 9, 2023 at 1:27 PM Robert Haas wrote: > On Tue, Oct 3, 2023 at 10:05 AM David G. Johnston > wrote: > >> 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. > >>

Re: CHECK Constraint Deferrable

2023-10-09 Thread Robert Haas
On Tue, Oct 3, 2023 at 10:05 AM David G. Johnston wrote: >> 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… >

Re: CHECK Constraint Deferrable

2023-10-09 Thread Robert Haas
On Mon, Oct 2, 2023 at 10:25 PM Tom Lane wrote: > But here we have a > feature whose only possible use is with constraints that *aren't* > immutable; else we might as well just check them immediately. I'm a little bit confused by this whole discussion because surely this statement is just complet

Re: CHECK Constraint Deferrable

2023-10-03 Thread David G. Johnston
On Monday, October 2, 2023, Andreas Joseph Krogh wrote: > På fredag 07. juli 2023 kl. 13:50:44, skrev Dilip Kumar < > dilipbal...@gmail.com>: > > On Wed, Jul 5, 2023 at 3:08 PM Himanshu Upadhyaya > wrote: > > > > Hi, > > > > Currently, there is no support for CHECK constraint DEFERRABLE in a > c

Re: CHECK Constraint Deferrable

2023-10-03 Thread Himanshu Upadhyaya
On Tue, Sep 19, 2023 at 4:14 PM Dean Rasheed wrote: > > I think we should be able to defer one constraint like in the case of > > foreign key constraint > > > > Agreed. It should be possible to have a mix of deferred and immediate > constraint checks. In the example, the tbl_chk_1 is set deferred

Re: CHECK Constraint Deferrable

2023-10-02 Thread Himanshu Upadhyaya
On Thu, Sep 14, 2023 at 9:57 AM vignesh C wrote: > 2) I was not sure, if the error message change was intentional: > 2a) > In Head: > CREATE FOREIGN TABLE t9(a int CHECK(a<>0) DEFERRABLE) SERVER s1; > ERROR: misplaced DEFERRABLE clause > LINE 1: CREATE FOREIGN TABLE t9(a int CHECK(a<>0) DEFERRAB

Re: CHECK Constraint Deferrable

2023-10-02 Thread Tom Lane
Vik Fearing writes: > On 10/2/23 21:25, Tom Lane wrote: >> Sorry for not weighing in on this before, but ... is this a feature >> we want at all? > For standards conformance, I vote yes. Only if we can actually implement it in a defensible way, which this patch is far short of accomplishing. >>

Re: CHECK Constraint Deferrable

2023-10-02 Thread Andreas Joseph Krogh
På fredag 07. juli 2023 kl. 13:50:44, skrev Dilip Kumar mailto:dilipbal...@gmail.com>>: On Wed, Jul 5, 2023 at 3:08 PM Himanshu Upadhyaya wrote: > > Hi, > > Currently, there is no support for CHECK constraint DEFERRABLE in a create table statement. > SQL standard specifies that CHECK constraint

Re: CHECK Constraint Deferrable

2023-10-02 Thread Vik Fearing
On 10/2/23 21:25, Tom Lane wrote: Himanshu Upadhyaya writes: V3 patch attached. Sorry for not weighing in on this before, but ... is this a feature we want at all? For standards conformance, I vote yes. We are very clear in the existing docs that CHECK conditions must be immutable [1], an

Re: CHECK Constraint Deferrable

2023-10-02 Thread David G. Johnston
On Mon, Oct 2, 2023 at 12:25 PM Tom Lane wrote: > Himanshu Upadhyaya writes: > > V3 patch attached. > > Sorry for not weighing in on this before, but ... is this a feature > we want at all? We are very clear in the existing docs that CHECK > conditions must be immutable [1], and that's not some

Re: CHECK Constraint Deferrable

2023-10-02 Thread Tom Lane
Himanshu Upadhyaya writes: > V3 patch attached. Sorry for not weighing in on this before, but ... is this a feature we want at all? We are very clear in the existing docs that CHECK conditions must be immutable [1], and that's not something we can easily relax because if they are not then it's u

Re: CHECK Constraint Deferrable

2023-10-02 Thread Himanshu Upadhyaya
On Mon, Oct 2, 2023 at 8:31 PM Himanshu Upadhyaya < upadhyaya.himan...@gmail.com> wrote: V3 patch attached. > -- Regards, Himanshu Upadhyaya EnterpriseDB: http://www.enterprisedb.com v3-0001-Implementation-of-CHECK-Constraint-to-make-it.patch Description: Binary data

Re: CHECK Constraint Deferrable

2023-10-02 Thread Himanshu Upadhyaya
On Tue, Sep 12, 2023 at 2:56 PM vignesh C wrote: > On Thu, 7 Sept 2023 at 17:26, Himanshu Upadhyaya > wrote: > > > > Attached is v2 of the patch, rebased against the latest HEAD. > > Thanks for working on this, few comments: > 1) "CREATE TABLE check_constr_tbl (i int CHECK(i<>0) DEFERRABLE, t >

Re: CHECK Constraint Deferrable

2023-09-19 Thread Dean Rasheed
On Fri, 15 Sept 2023 at 08:00, vignesh C wrote: > > On Thu, 14 Sept 2023 at 15:33, Himanshu Upadhyaya > wrote: > > > > On Thu, Sep 14, 2023 at 9:57 AM vignesh C wrote: > >> > >> postgres=*# SET CONSTRAINTS tbl_chk_1 DEFERRED; > >> SET CONSTRAINTS > >> postgres=*# INSERT INTO tbl values (1); > >

Re: CHECK Constraint Deferrable

2023-09-14 Thread vignesh C
On Thu, 14 Sept 2023 at 15:33, Himanshu Upadhyaya wrote: > > > > On Thu, Sep 14, 2023 at 9:57 AM vignesh C wrote: >> >> 3) Insert check is not deferred to commit: >> This insert check here is deferred to commit: >> postgres=# CREATE TABLE tbl (i int ) partition by range (i); >> CREATE TABLE tbl_1

Re: CHECK Constraint Deferrable

2023-09-14 Thread Himanshu Upadhyaya
On Thu, Sep 14, 2023 at 9:57 AM vignesh C wrote: > 3) Insert check is not deferred to commit: > This insert check here is deferred to commit: > postgres=# CREATE TABLE tbl (i int ) partition by range (i); > CREATE TABLE tbl_1 PARTITION OF tbl FOR VALUES FROM (0) TO (10); > CREATE TABLE tbl_2 PART

Re: CHECK Constraint Deferrable

2023-09-13 Thread Himanshu Upadhyaya
Thanks for the review comments. On Tue, Sep 12, 2023 at 2:56 PM vignesh C wrote: > On Thu, 7 Sept 2023 at 17:26, Himanshu Upadhyaya > wrote: > > > > Attached is v2 of the patch, rebased against the latest HEAD. > > Thanks for working on this, few comments: > 1) "CREATE TABLE check_constr_tbl (i

Re: CHECK Constraint Deferrable

2023-09-13 Thread vignesh C
On Thu, 7 Sept 2023 at 17:26, Himanshu Upadhyaya wrote: > > Attached is v2 of the patch, rebased against the latest HEAD. Few issues: 1) Create domain fails but alter domain is successful, I feel we should support create domain too: postgres=# create domain d1 as int check(value<>0) deferrable; E

Re: CHECK Constraint Deferrable

2023-09-12 Thread vignesh C
On Thu, 7 Sept 2023 at 17:26, Himanshu Upadhyaya wrote: > > Attached is v2 of the patch, rebased against the latest HEAD. Thanks for working on this, few comments: 1) "CREATE TABLE check_constr_tbl (i int CHECK(i<>0) DEFERRABLE, t text)" is crashing in windows, the same was noticed in CFBot too:

Re: CHECK Constraint Deferrable

2023-09-11 Thread Himanshu Upadhyaya
On Fri, Sep 8, 2023 at 1:23 PM Dilip Kumar wrote: > 2. > - if ((failed = ExecRelCheck(resultRelInfo, slot, estate)) != NULL) > + if ((failed = ExecRelCheck(resultRelInfo, slot, estate, > checkConstraint, &recheckConstraints)) != NULL && !recheckConstraints) > > > Why recheckConstraints need to ge

Re: CHECK Constraint Deferrable

2023-09-08 Thread Dilip Kumar
On Thu, Sep 7, 2023 at 1:25 PM Himanshu Upadhyaya wrote: > > Attached is v2 of the patch, rebased against the latest HEAD. I have done some initial reviews, and here are my comments. More detailed review later. Meanwhile, you can work on these comments and fix all the cosmetics especially 80 ch

Re: CHECK Constraint Deferrable

2023-09-07 Thread Himanshu Upadhyaya
Attached is v2 of the patch, rebased against the latest HEAD. Thanks, Himanshu From cf6057ebeffd026ae075ec43d573eca1164eff5b Mon Sep 17 00:00:00 2001 From: Himanshu Upadhyaya Date: Thu, 7 Sep 2023 13:19:14 +0530 Subject: [PATCH v2] Implementation of "CHECK Constraint" to make it Deferrable. ---

Re: CHECK Constraint Deferrable

2023-07-07 Thread David G. Johnston
On Friday, July 7, 2023, Himanshu Upadhyaya wrote: > I can think of one scenario, as below > > 1) any department should have an employee > 2)any employee should be assigned to a department > so, the employee table has a FK to the department table, and another check > constraint should be added to

Re: CHECK Constraint Deferrable

2023-07-07 Thread Himanshu Upadhyaya
I can think of one scenario, as below 1) any department should have an employee 2)any employee should be assigned to a department so, the employee table has a FK to the department table, and another check constraint should be added to the department table to ensure there should be one/more employe

Re: CHECK Constraint Deferrable

2023-07-07 Thread Dilip Kumar
On Wed, Jul 5, 2023 at 3:08 PM Himanshu Upadhyaya 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 SQ