Specialize 'select-or-insert' and 'update-or-insert'
See original GitHub issueRecent work on adding the select-or-insert and update-or-insert idioms to EdgeQL (#1628, #684) spawned a discussion on whether using a general-purpose conditional operator ??
is a good idea after all.
The approach committed in #1628 has lots of technical limitations, and, although most of those can be fixed with more work, the main issue with it remains: it gives a misleading appearance of generic support for conditional DML which is impossible as long as it is in PostgreSQL.
For this reason I propose reverting the select-or-insert and update-or-insert to a specialized form of the INSERT
statement:
INSERT Type { <shape> }
UNLESS CONFLICTS [ <conflict-target> [ ELSE <alternative-stmt> ] ]
where alternative-stmt
may be any other query, including UPDATE
or DELETE
.
This is semantically much closer to PostgreSQL’s INSERT ... ON CONFLICT ...
and allows explicit specification of the conflict target (i.e. the constraint expression).
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
I see two different spellings used in this issue and its comments:
UNLESS CONFLICTS
andUNLESS CONFLICT
. I’m +1 for the latter. Also, I think that the optional<conflict-target>
should be prefixed byON
.No,
DELETE UNLESS CONFLICT
would have a drastically different implementation and the use case for it isn’t clear.