Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: INSERT ON CONFLICT DO NOTHING reports incorrect number of inserted rows #21155

Closed
jordanlewis opened this issue Jan 2, 2018 · 2 comments
Assignees
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL

Comments

@jordanlewis
Copy link
Member

root@:26257/test> create table test (a int primary key);
CREATE TABLE
root@:26257/test> insert into test values (1) on conflict(a) do nothing;
INSERT 1
root@:26257/test> insert into test values (1) on conflict(a) do nothing;
INSERT 1

The second insert should return INSERT 0, as no inserts were performed. This is what Postgres does as well:

jordan=# create table test (a int primary key);
CREATE TABLE
jordan=# insert into test values(1) on conflict do nothing;
INSERT 0 1
jordan=# insert into test values(1) on conflict do nothing;
INSERT 0 0

Found via #20985.

@jordanlewis jordanlewis added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Jan 2, 2018
@jordanlewis
Copy link
Member Author

For what it's worth, it does report the correct number of rows when executed with a RETURNING option:

root@:26257/test> insert into test values (1) on conflict(a) do nothing returning a;
+---+
| a |
+---+
+---+
(0 rows)

@knz knz self-assigned this Apr 28, 2018
@knz
Copy link
Contributor

knz commented Apr 28, 2018

I fixed that in #23373

@knz knz closed this as completed Apr 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL
Projects
None yet
Development

No branches or pull requests

2 participants