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 $1 in an aggregate FILTER.
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
Confirmed the fixture fails on unmodified main with column "activity_at" does not exist.
go test ./internal/endtoend -run 'TestReplay/base/cte_filter_alias' -count=1
go test ./internal/compiler ./internal/endtoend -run 'TestReplay/base/cte_filter_alias' -count=1
Regenerated the existing cte_update fixture 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.
Closing as a duplicate. #4430 already fixes CTE-column lookup in parameter inference and tracks the ambiguity concern with sharing the regular-table type map; #3585 is the existing issue. I should have found those before opening this PR.
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
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 $1 in an aggregate FILTER.
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
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.