Re: Partial update on an postgres upsert violates constraint

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Partial update on an postgres upsert violates constraint
Date: 2016-11-23 17:53:04
Message-ID: 88657daf-fa5c-d728-93b6-d53dcfb10abd@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Mead 2016-11-23 17:53:07 Re: Methods to quiesce PostgreSQL DB without configuring log archival
Previous Message Melvin Davidson 2016-11-23 16:53:26 Thank you