Re: INSERT ... ON CONFLICT {UPDATE | IGNORE} - Mailing list pgsql-hackers

From Anssi Kääriäinen
Subject Re: INSERT ... ON CONFLICT {UPDATE | IGNORE}
Date
Msg-id 1417760835.22478.80.camel@TTY32
Whole thread Raw
In response to Re: INSERT ... ON CONFLICT {UPDATE | IGNORE}  (Peter Geoghegan <pg@heroku.com>)
Responses Re: INSERT ... ON CONFLICT {UPDATE | IGNORE}  (Peter Geoghegan <pg@heroku.com>)
List pgsql-hackers
On Thu, 2014-12-04 at 10:27 -0800, Peter Geoghegan wrote:

> I think that the standard for adding a new system attribute ought to
> be enormous. The only case where a new one was added post-Postgres95
> was "tableoid". I'm pretty sure that others aren't going to want to do
> it that way. Besides, I'm not entirely convinced that this is actually
> an important distinction to expose.

For Django's use case this is a requirement. We must inform the user if
the save() action created a new row or if it modified an existing one.

Another way to do this would be to expose the "excluded" alias in the
returning clause. All columns of the excluded alias would be null in
the case of insert (especially the primary key column), and thus if a
query   insert into foobar values(2, '2') on conflict (id) update set other_col=excluded.other_col returning
excluded.id
returns a non-null value, then it was an update.
- Anssi





pgsql-hackers by date:

Previous
From: Adam Brightwell
Date:
Subject: check-world failure: dummy_seclabel
Next
From: Amit Kapila
Date:
Subject: Re: On partitioning