Repository navigation
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.
Fixes #4198
Summary
Queries selecting from a
VALUESsubquery or CTE with column aliases (for example,SELECT * FROM (VALUES ('SAVED'), ('IDLE')) AS pending_sale_status(status)inside a CTE) failed during compilation or star expansion with two separate gaps:Missing output-column inference for
VALUESlists:internal/compiler/output_columns.go),outputColumnshandledSelectStmt.TargetListandUNIONbranches (Larg), but fell through with an empty column slice whenSelectStmt.ValuesListswas populated.internal/core/analyzer/analyzer.go),typeValuesListstype-checked the cell expressions without populatinga.columns(column1,column2, ...).column1..columnNcolumns across all rows inValuesLists, wideningNULLcells into nullable types when another row supplies a concrete type.Subquery column aliases ignored on
RangeSubselectinsourceTables:sourceTablesininternal/compiler/output_columns.goreadn.Alias.Aliasnamefor the relation name (without guarding nilAliasname), and ignoredn.Alias.Colnames(e.g.AS pending_sale_status(status)orAS renamed(item_id, item_name)).n.Alias.Colnames(matchingbindRangeSubselectin the core analyzer).Changes
internal/compiler/output_columns.go: AddvaluesColumnsforSelectStmt.ValuesListsand applyRangeSubselect.Alias.ColnamesinsourceTables.internal/core/analyzer/analyzer.go: Populatea.columns(column1..columnN, merged types/nullability) insidetypeValuesLists.internal/endtoend/testdata/cte_values/: Add end-to-end PostgreSQL (pgx/v5) golden test covering the#4198VALUESCTE, mixed-type/nullable multi-rowVALUES, directWITH cte(a, b) AS (VALUES ...)aliasing, defaultcolumn1/column2naming, andRangeSubselectcolumn aliases.Verification
Run locally with Go 1.26.5 after the final edit:
gofmt -l internal/compiler/output_columns.go internal/core/analyzer/analyzer.go— cleango vet ./...— passedCGO_ENABLED=0 go build ./...— passedgo test -race -count=1 ./internal/compiler/... ./internal/core/...— passedSQLC_TEST_CORE=1 go test -count=1 -v ./internal/endtoend -run 'TestReplay/.*/cte_values'— passed acrossbase,managed-db(live PostgreSQL), andcorecontextsgo test -count=1 ./internal/endtoend -run 'TestReplay/base|TestFormat|TestJsonSchema'— passedcd internal/endtoend/testdata && go build ./cte_values/...— passed