Repository navigation
fix(syntax): name VALUES and UNPIVOT items by their alias in query scopes - #275
Merged
Merged
Conversation
…opes A VALUES list written without parentheses, as in FROM VALUES (1), (2) AS v(a), and an aliased UNPIVOT carry their alias on their own node. The scope builder read aliases only from tables, derived tables, aliases, joined tables and PIVOT, so neither item was a relation of its query, and a reference such as v.a looked like one to a relation out of sight. In parentheses the list is a derived table and was found.
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.
Why
Expression::query_scopesleft two FROM items out of their query's relations, because their alias sits on their own node:FROM VALUES (1), (2) AS v(a)FROM orders UNPIVOT (val FOR k IN (a, b)) AS uSo
qualified_columnsreportedv.aandu.kas reading a relation that is not in sight. SQLClean 0.12.0, which runs its relation Rules on these scopes, reports such references as SQLCLEAN029 findings on valid SQL. The parenthesisedFROM (VALUES ...) AS v(a)was found, because it is a derived table.Changes
relation()in the scope builder reads the alias ofExpression::ValuesandExpression::Unpivot.query_scopesis used only by downstream Rules, not by conversion, so no converted output changes.Verification
cargo test -p sqlquack-parse --lib given_qualified_columns_when_scoped: the new cases fail without the change and pass with it.make check-ci.