playground icon indicating copy to clipboard operation
playground copied to clipboard

Incorrect ON CONFLICT when using composite primary key

Open johannes-riecken opened this issue 1 year ago • 0 comments

Explain your user case and expected results

I'm using a composite primary key for a table that references a list of entities in another table.

The error I get is

2023/10/02 15:24:09 testing postgres...

2023/10/02 15:24:10 gorm-playground/main_test.go:13 ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
[0.952ms] [rows:0] INSERT INTO "tags" ("pet_first_name","pet_last_name","name") VALUES ('Hasso','McDog','foo') ON CONFLICT DO UPDATE SET "pet_first_name"="excluded"."pet_first_name","pet_last_name"="excluded"."pet_last_name"

2023/10/02 15:24:10 gorm-playground/main_test.go:13 ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
[3.761ms] [rows:1] INSERT INTO "pets" ("first_name","last_name") VALUES ('Hasso','McDog')
--- FAIL: TestGORM (0.00s)
    main_test.go:14: ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
FAIL
FAIL	gorm.io/playground	0.238s

johannes-riecken avatar Oct 02 '23 13:10 johannes-riecken