Fix parameter inference for aliased CTE columns - #4586
Closed
riordanpawley wants to merge 1 commit into
Closed
Conversation
riordanpawley
force-pushed
the
fix-cte-alias-parameter-resolution
branch
from
August 27, 2026 14:29
583d559 to
12295d5
Compare
Author
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
Parameter inference indexed catalog tables but skipped common-table expressions. As a result, a bind parameter compared with an aliased CTE column failed compilation with
column "activity_at" does not exist, even though output-column analysis had already resolved the CTE.This change indexes the resolved CTE columns in the same parameter-inference map used for catalog tables. The end-to-end fixture is the minimal reproduction: one base column renamed in a CTE and referenced beside
$1in an aggregateFILTER.User-facing changes
sqlc now infers parameters compared with aliased CTE columns instead of rejecting the query as an unknown column.
Existing CTE update parameters now use their resolved non-null column types instead of nullable fallback wrappers; the corresponding golden output is updated.
Validation
mainwithcolumn "activity_at" does not exist.go test ./internal/endtoend -run 'TestReplay/base/cte_filter_alias' -count=1go test ./internal/compiler ./internal/endtoend -run 'TestReplay/base/cte_filter_alias' -count=1cte_updatefixture to record its newly inferred non-null parameter types.Risk
Low. The new indexing path runs only when a range variable resolves as a CTE rather than a catalog table. It carries the CTE's already-resolved names and types into existing parameter inference. Callers generated from affected CTE updates may move from nullable wrappers to scalar parameters when the source columns are non-null.