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 error #20985

Closed
baitxo opened this issue Dec 21, 2017 · 5 comments
Closed

sql: INSERT ... ON CONFLICT DO NOTHING error #20985

baitxo opened this issue Dec 21, 2017 · 5 comments
Labels
C-question A question rather than an issue. No code/spec/doc change needed. O-community Originated from the community

Comments

@baitxo
Copy link

baitxo commented Dec 21, 2017

Server log (just one node on the cluster):

I171221 12:42:33.080411 1 util/log/clog.go:992  [config] binary: CockroachDB CCL v1.1.3 (darwin amd64, built 2017/11/27 14:52:00, go1.9.2)
I171221 12:42:33.080411 1 util/log/clog.go:992  [config] arguments: [cockroach start --insecure]

Expected (PG behavior):

INSERT ... ON CONFLICT DO NOTHING executes normally

Current state:

INSERT ... ON CONFLICT DO NOTHING raises:
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification

@baitxo baitxo changed the title INSERT ... ON CONFLICT DO NOTHING error sql: INSERT ... ON CONFLICT DO NOTHING error Dec 21, 2017
@jordanlewis
Copy link
Member

@baitxo, can you give a complete example including the table schema that's being inserted into as well as example values?

@baitxo
Copy link
Author

baitxo commented Dec 22, 2017

Hi @jordanlewis,

Hope it helps,

cockroach sql --insecure -e "CREATE DATABASE insert_test" 
cockroach sql --insecure -e "CREATE TABLE test (user_id INT PRIMARY KEY, user_email STRING)" --database=insert_test
cockroach sql --insecure -e "INSERT INTO test VALUES (1, 'test_email') ON CONFLICT DO NOTHING" --database=insert_test

@glerchundi
Copy link

@jordanlewis friendly ping.

Still happening on the latest unstable release: v2.0-alpha.20171218.

@jordanlewis
Copy link
Member

Sorry for the delay.

You currently need to explicitly specify the conflict columns:

INSERT INTO test VALUES (1, 'test_email') ON CONFLICT (user_id) DO NOTHING

@baitxo
Copy link
Author

baitxo commented Jan 8, 2018

Thanks @jordanlewis!

@baitxo baitxo closed this as completed Jan 8, 2018
@jordanlewis jordanlewis added C-question A question rather than an issue. No code/spec/doc change needed. O-community Originated from the community and removed O-deprecated-community-questions labels Apr 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question A question rather than an issue. No code/spec/doc change needed. O-community Originated from the community
Projects
None yet
Development

No branches or pull requests

4 participants