question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specialize 'select-or-insert' and 'update-or-insert'

See original GitHub issue

Recent 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:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
1st1commented, Aug 11, 2020

I see two different spellings used in this issue and its comments: UNLESS CONFLICTS and UNLESS CONFLICT. I’m +1 for the latter. Also, I think that the optional <conflict-target> should be prefixed by ON.

INSERT Type { <shape> } 
UNLESS CONFLICT [ ON <conflict-target> [ ELSE <alternative-stmt> ] ]
0reactions
elpranscommented, Aug 14, 2020

No, DELETE UNLESS CONFLICT would have a drastically different implementation and the use case for it isn’t clear.

Read more comments on GitHub >

github_iconTop Results From Across the Web

php - What are the specifics for Laravel Query Builder's ...
Insert or update a record matching the attributes, and fill it with values. updateOrInsert(array $attributes, array $values = []).
Read more >
SelectOrInsert · Issue #573 · go-pg/pg - GitHub
Hi! I have a table with two unique fields. pffo_id and path. Since the id is autogenerated, I would expect every time I...
Read more >
How to use updateOrInsert() in Laravel - Educative.io
updateOrInsert () is a query builder used to alter values of your database, in this case it either creates a new record or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found