Repository navigation
feat(analysis): accept ON CONFLICT upserts on inserts - #59
Merged
Merged
Conversation
Analyze INSERT ... ON CONFLICT (columns) DO NOTHING and DO UPDATE SET on :exec and returning inserts. Target, assigned, and EXCLUDED columns resolve against the inserted table, and DO UPDATE placeholders are typed like UPDATE assignments and bound after the VALUES row in textual order. Constraint targets, expression, collated, or operator-class target elements, target predicates, and DO UPDATE ... WHERE are rejected on every insert.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Inserts can now be written as PostgreSQL upserts.
INSERT ... ON CONFLICT (columns) DO NOTHINGandON CONFLICT (columns) DO UPDATE SET ...compile on:execand returning inserts, with every placeholder typed and bound once per textual occurrence, so the common insert-or-update idiom no longer needs a workaround. Conflict forms the analyzer cannot describe are rejected on every insert instead of passing through unchecked on:exec.Changes
DO NOTHING, which binds only theVALUESrow.DO UPDATE SETassignments analyzed exactly likeUPDATEassignments: one column at a time, where a value is a placeholder typed by its column, a cast placeholder typed by its cast,EXCLUDED.column(resolved against the inserted table), or any other expression passed through as written.DO UPDATEplaceholders after theVALUESplaceholders in textual order. A repeated named placeholder binds at each occurrence.RETURNING, includingRETURNING *resolving the table's shared row record.:execand returning inserts alike, a missing target,ON CONFLICT ON CONSTRAINT, an expression, collated, or operator-class target element, a target predicate, andDO UPDATE ... WHERE. Reject unknown target, assigned, orEXCLUDEDcolumns.RETURNING, over a new row and then a conflicting one.DO NOTHING ... RETURNINGcardinality, and the rejected forms.Scope and non-goals
EXCLUDEDreference nested inside a larger expression is not resolved, the same as other computed write values.MERGE,ON DUPLICATE KEY, multi-row andSELECT-sourced inserts are unchanged and unsupported.