ON CONFLICT DO NOTHING RETURNING

From: Peter Devoy <peter(at)3xe(dot)co(dot)uk>
To: "Psql_General (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: ON CONFLICT DO NOTHING RETURNING
Date: 2016-03-14 19:28:24
Message-ID: CABoFc_hxX7F9n_nTGFP5-9y-Qy5v9_Wgn5j4DSaD8q-Gx0g=6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all

Is it possible to have ON CONFLICT DO NOTHING RETURNING or must I use DO
UPDATE?

E.g. if the 'name' column of my 'animals' table is unique it seems a little
silly having to do an arbitrary update to get an ID from the row:

INSERT INTO animals (name) VALUES ('dog') ON CONFLICT (name) DO UPDATE SET
name='dog' RETURNING animal_id;

Is there a reason DO NOTHING was not developed for use with RETURNING?

Either way, upsert is great, I am glad we have it now.

Kind regards

Peter Devoy

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2016-03-14 20:15:58 Re: Unexpected result using floor() function
Previous Message Francisco Olarte 2016-03-14 19:26:02 Re: Suppress decimal point like digits in to_char?