In a Postgresql 9.6 DB, there is a existing table named X
that has four columns, a
, b
, c
, and d
with indices setup like this:
"uidx_a_b" UNIQUE, btree (a, b) WHERE c IS NULL AND d IS NULL
"uidx_a_c" UNIQUE, btree (a, b, c) WHERE c IS NOT NULL AND d IS NULL
"uidx_a_d" UNIQUE, btree (a, b, c, d) WHERE c IS NOT NULL AND d IS NOT NULL
I don't know why this was done as it was done by someone long gone and before I had to modify it.
I am trying to get the syntax correct for specifying all three of these in an ON CONFLICT statement. I tried every variation I could think of all with error. The Postgresql Documentation indicates this is possible, specifically the [, ...]
described in the conflict_target
here:
( { index_column_name | ( index_expression ) } [ COLLATE collation ] [ opclass ] [, ...] )
Also, this blog from one of the committers says so. Finally, I looked at this unit test for the functionality again to no avail! Having thus given up, I am turning to SO to seek help.
This is what I believe is the closest syntax I tried that should work:
ON CONFLICT (
((a, b) WHERE c IS NULL AND d IS NULL),
((a, b, c) WHERE c IS NOT NULL AND d IS NULL),
((a, b, c, d) WHERE release_id IS NOT NULL AND d IS NOT NULL)
)
However this fails with:
ERROR: syntax error at or near ","
While I am open to suggestions to improve the design
of those indices, I really want to know if there is a valid syntax for specifying the ON CONFLICT clause as it seems there should be!