Repository navigation
feat(analysis): analyze CTEs and FROM subqueries as derived sources - #79
Merged
Merged
Conversation
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
Common table expressions and
FROM/JOINsubqueries now compile as typed sources. A source that names aWITHclause, or an aliased subquery, exposes the result columns of its own analyzedSELECT, so placeholders inside those bodies are typed and named from columns instead of requiring casts, and everyWITHbody of every statement is checked against the schema.Changes
FROMorJOINsource whose unqualified name matches aWITHclause in scope (case-insensitively, innermost first) reads that clause; an aliased subquery source reads its body. Their columns carry the body's names, types, enum, array, and nullability facts, and a left join makes every column nullable.SELECT *over one returns a query-specific result even when it is named like a table.WITHbody and subquery source is analyzed like a top-levelSELECT: sources, joins, projection rules, andON/WHERE/LIMIT/OFFSETplaceholder typing. AWITHbody sees earlier clauses and enclosing ones and reads the schema table it is named like; a subquery source sees no outer source.WITHclause ofSELECT,INSERT,UPDATE, andDELETEis analyzed in order, read or not, and a returning write may now declareWITHclauses. An indexed cast placeholder in aWITHbody is named from its clause, soorders.total = $1::numericnamestotal.WITH RECURSIVE is not supported.;A data-modifying statement in WITH is not supported; run it as a query of its own.;A subquery in FROM requires an alias, such as (SELECT ...) AS recent.;A column list on <name> is not supported; alias the columns in its SELECT instead.; andDerived source <name> has more than one column named <column>; give each a distinct alias.A set operation orVALUESbody keeps its existing diagnostic.Scope and non-goals
EXISTS,IN (SELECT ...), scalar comparison subqueries, and subqueries in projections,GROUP BY,HAVING,ORDER BY, written values, andRETURNINGkeep their current handling.VALUES,INSERT ... SELECT,UPDATE ... FROM, andDELETE ... USINGremain rejected.LATERALsources and doubly parenthesized sources keep their existing rejections.WITH-body cast parameters.