Баг / улучшение в INSERT ON CONFILCT?

From: Warstone(at)list(dot)ru <warstone(at)list(dot)ru>
To: pgsql-ru-general(at)lists(dot)postgresql(dot)org
Subject: Баг / улучшение в INSERT ON CONFILCT?
Date: 2018-08-15 14:50:08
Message-ID: 1534344608.996233254@f56.i.mail.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-ru-general


=> CREATE TABLE test (
  id BIGSERIAL NOT NULL PRIMARY KEY,
  name TEXT NOT NULL UNIQUE,
  value TEXT
);
CREATE TABLE

=> INSERT INTO test (name, value) VALUES ('test', '1');
INSERT 0 1

=> INSERT INTO test (name, value) VALUES ('test', '1');
ERROR:  duplicate key value violates unique constraint "test_name_key"
DETAIL:  Key (name)=(test) already exists.

=> INSERT INTO test (name, value) VALUES ('test', '1') ON CONFLICT DO NOTHING;
INSERT 0 0

=> INSERT INTO test (name, value) VALUES ('test', '1') ON CONFLICT DO NOTHING RETURNING id;
 id
----
(0 rows)

=> INSERT INTO test (name, value) VALUES ('test', '1') ON CONFLICT (name) DO UPDATE SET name = 'test' RETURNING id;
 id
----
  1
(1 row)

INSERT 0 1

=> SELECT version();
                                              version
---------------------------------------------------------------------------------------------------
 PostgreSQL 9.6.6 on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18) 6.3.0 20170516, 64-bit
(1 row)

Куда писать чтобы и в случае DO NOTHING id возвращался?.. Так как кажется - баг.

Responses

Browse pgsql-ru-general by date

  From Date Subject
Next Message Sergei Kornilov 2018-08-15 15:13:25 Re: Баг / улучшение в INSERT ON CONFILCT?
Previous Message vlads 2018-08-08 03:54:22 Внешние подключения