Repository navigation
feat(analysis): analyze UPDATE ... FROM and DELETE ... USING sources - #82
Merged
Merged
Conversation
Added sources (tables, CTEs, and aliased subqueries) join the target in the WHERE scope, so their columns type and name placeholders, and a join inside FROM types its condition over its own comma-separated item. RETURNING may return a column of any source, and RETURNING <target>.* returns the target's shared row on every write. A bare * on a joined write and a wildcard of another source are rejected, and the remaining multi-table UPDATE and joined DELETE forms get messages naming the supported clause.
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
UPDATE ... FROMandDELETE ... USINGnow compile. Their added sources are analyzed like a read's sources, so placeholders that compare against those columns are typed and named from them without casts, andRETURNINGcan return columns of any source. The only full row a joined write returns is the target's, writtenRETURNING <target>.*, which keeps the target's shared row record.Changes
UPDATE ... FROMaccepts one source followed by inner or left joins or by further comma-separated sources.DELETE ... USINGaccepts a comma-separated list. Each added source is a table, aWITHclause of the write, or an aliased subquery, and subquery and CTE bodies type their own placeholders.WHEREpredicate sees the target and every added source as one level, with the write'sWITHclauses in scope for predicate subqueries. Ambiguous unqualified columns and repeated exposed names are rejected.FROMsees only its own comma-separated item, up to its joined source, as PostgreSQL scopes it. Naming the target or an earlier item there is rejected as an unknown source qualifier.RETURNING, a direct column of any source is typed from its column and is nullable when its source is left-joined.RETURNING <target>.*returns the target's shared<TableName>Rowrecord on anyINSERT,UPDATE, orDELETE. Written beside other items, it contributes the target's columns to a query-specific result.RETURNINGforms are rejected with messages that say what to write instead:RETURNING *on a joined writeUPDATE a, b,UPDATE a JOIN b ... SET, andDELETE a FROM a JOIN bstay rejected. Their messages now point toUPDATE ... FROMandDELETE ... USING.SET, the added sources and their join conditions, andWHERE, and the executable SQL is unchanged.RETURNINGrules, and the two shapes are removed from the reference service's unsupported-query catalogue.Scope and non-goals
USINGis not supported, because the SQL parser cannot read one there.SETvalue expressions are not analyzed beyond typing a placeholder from the column it assigns. Other values reach the database as written.RETURNINGkeep their existing handling, and the computed-RETURNINGdiagnostic wording is unchanged.