Re: Partial update on an postgres upsert violates constraint

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas Terrius <gotenwinz99(at)gmail(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Kim Rose Carlsen <krc(at)hiper(dot)dk>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Partial update on an postgres upsert violates constraint
Date: 2016-11-23 20:19:42
Message-ID: 29141.1479932382@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andreas Terrius <gotenwinz99(at)gmail(dot)com> 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 expect this to be able to work. The data
you are supplying is insufficient to satisfy the INSERT case, so why do
you think that an insert-or-update should be possible?

ISTM that you could try the UPDATE first and notice whether it updates
any rows or not. I'm not sure what you're going to do if it doesn't,
though, since you still haven't got enough data to do an INSERT.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Poul Kristensen 2016-11-23 20:31:19 Re: Postgresql 9.5 and Shell scripts/variables vs. C programming/defining a value to be used
Previous Message Andreas Kretschmer 2016-11-23 20:18:18 Re: Backup "Best Practices"