From: rwestlun@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13886: When INSERT ON CONFLICT DO UPDATE updates, it returns INSERT rather than UPDATE
Date: Mon, 25 Jan 2016 07:48:06 +0000
Message-ID: <20160125074806.2555.44482@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 13886
Logged by: Randy Westlund
Email address: rwestlun@gmail.com
PostgreSQL version: 9.5.0
Operating system: FreeBSD-10.2
Description:
Situation: When INSERT ON CONFLICT DO UPDATE does an update.
Current behavior: Postgres returns "INSERT"
Expected behavior: Postgres should return "UPDATE"
Steps:
uvbase=> create table test ( id integer primary key, str text );
CREATE TABLE
uvbase=> insert into test (id, str) values (1, 'insert') on conflict(id) do
update set str = 'update';
INSERT 0 1
uvbase=> select * from test;
id | str
----+--------
1 | insert
(1 row)
uvbase=> insert into test (id, str) values (1, 'insert') on conflict(id) do
update set str = 'update';
INSERT 0 1
uvbase=> select * from test;
id | str
----+--------
1 | update
(1 row)
I believe postgres should be returning "UPDATE" here instead of "INSERT"
because I see no way to know which operation took place. I believe my only
options at the moment are using a second query or adding a column like
"just_created BOOLEAN DEFAULT true", setting it to false in the UPDATE
clause, and returning it.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: rwestlun@gmail.com
Subject: Re: BUG #13886: When INSERT ON CONFLICT DO UPDATE updates, it returns INSERT rather than UPDATE
In-Reply-To: <20160125074806.2555.44482@wrigleys.postgresql.org>
References: <20160125074806.2555.44482@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox