Allow ELSE after UNLESS CONFLICT
Summary
There's currently no way to allow ELSE statements on objects with two or more property constraints, take this object as an example:
type Person {
required property email -> str {
constraint exclusive;
}
required property phone_number-> str {
constraint exclusive;
}
}
If you wanted to preform an insert with an else clause, you would have to add the UNLESS CONFLICT ON ... clause like so:
insert Person { ... } unless conflict on ??? else (...)
but since we're working with property level constraints, there's not direct way of selecting 2 or more properties for the UNLESS CONFLICT statement. This can be solved by adding an object level constraint like so:
type Person {
required property email -> str;
required property phone_number-> str;
constraint exclusive on ((.email, .phone_number));
}
Another solution (and why I'm opening this github issue) is to make the [ON ...] optional. This allows us to write a working query like so:
insert Person { ... } unless conflict else (...)
This implicit solution would find whatever constraints exist on Person and apply that to the CONFLICT statement.
Yeah, I think this should be possible.
I actually implemented this in https://github.com/edgedb/edgedb/pull/2196 and then backed it out in https://github.com/edgedb/edgedb/pull/2202.
The thing that is potentially weird about it is that unlike currently, multiple objects might need to be selected in the ELSE block. If I recall correctly, I think I wasn't too bothered by that but others were nervous? I think that probably to mitigate the weirdness, we can make it work only for select and not for dml?
Oh, like with #4302, it has the problem that some of the conflicting objects might have a different type, also