Re: [GENERAL] Partial update on an postgres upsert violates constraint

2016-11-23 Thread Tom Lane
Andreas Terrius writes: > Is there any way to check whether the row already exists before checking > constraints ? I still want it to fail if it turns out to be a new row > (which would violate the not null constraint), but updates the row if it > already exists. I'm not really sure why you expec

Re: [GENERAL] Partial update on an postgres upsert violates constraint

2016-11-23 Thread John R Pierce
On 11/21/2016 2:32 AM, Andreas Terrius wrote: Is there any way to check whether the row already exists before checking constraints ? I still want it to fail if it turns out to be a new row (which would violate the not null constraint), but updates the row if it already exists. just do an upda

Re: [GENERAL] Partial update on an postgres upsert violates constraint

2016-11-23 Thread Andreas Terrius
Is there any way to check whether the row already exists before checking constraints ? I still want it to fail if it turns out to be a new row (which would violate the not null constraint), but updates the row if it already exists. Since if that is not possible, I would need to do a query to deter

Re: [GENERAL] Partial update on an postgres upsert violates constraint

2016-11-21 Thread Adrian Klaver
On 11/21/2016 02:32 AM, Andreas Terrius wrote: Is there any way to check whether the row already exists before checking constraints ? I still want it to fail if it turns out to be a new row (which would violate the not null constraint), but updates the row if it already exists. Since if that is

Re: [GENERAL] Partial update on an postgres upsert violates constraint

2016-11-19 Thread Tom Lane
Adrian Klaver writes: > ... So looks like constraints are checked before you get to the ON CONFLICT > section. Right. ON CONFLICT is a means for dealing with duplicate-key errors in the specified (or inferred) unique index. It is *not* an all-purpose error catcher. In the case at hand, the gi

Re: [GENERAL] Partial update on an postgres upsert violates constraint

2016-11-19 Thread Adrian Klaver
On 11/19/2016 11:33 AM, Kim Rose Carlsen wrote: >> AFAIK, EXCLUDED is only available in a trigger function: > >> >> https://www.postgresql.org/docs/9.5/static/trigger-definition.html >> >> You are using EXCLUDED in a regular function so it would not be found. >> >> Can you also show the failure f

Re: [GENERAL] Partial update on an postgres upsert violates constraint

2016-11-19 Thread Kim Rose Carlsen
> AFAIK, EXCLUDED is only available in a trigger function: > > https://www.postgresql.org/docs/9.5/static/trigger-definition.html > > You are using EXCLUDED in a regular function so it would not be found. > > Can you also show the failure for your alternate method? >From the manual https://www.po

Re: [GENERAL] Partial update on an postgres upsert violates constraint

2016-11-19 Thread Adrian Klaver
On 11/17/2016 10:13 PM, Andreas Terrius wrote: Hi, Basically I wanted to do a partial update inside pg (9.5), but it seems that a partial update fails when not all of constraint is fulfilled (such as the not null constraint) Below are the sql queries I used, |CREATETABLEjobs (id integer PRIMARY