Re: Partial update on an postgres upsert violates constraint - Mailing list pgsql-general

From John R Pierce
Subject Re: Partial update on an postgres upsert violates constraint
Date
Msg-id 88657daf-fa5c-d728-93b6-d53dcfb10abd@hogranch.com
Whole thread Raw
In response to Re: Partial update on an postgres upsert violates constraint  (Andreas Terrius <gotenwinz99@gmail.com>)
List pgsql-general
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 update.  if the row doesn't exist, it will fail, you then
rollback the transaction or savepoint.

> Since if that is not possible, I would need to do a query to determine
> whether the row exists in the database which kinda eliminates the use
> of upsert. (in this case, partial upsert).

in general, anything that relies on those sorts of checks will fail
under concurrent loads.



--
john r pierce, recycling bits in santa cruz



pgsql-general by date:

Previous
From: Scott Mead
Date:
Subject: Re: Methods to quiesce PostgreSQL DB without configuring log archival
Next
From: Israel Brewster
Date:
Subject: Backup "Best Practices"