Validate unknown columns in SELECT WHERE clauses (fixes #4264)#4403
Open
lawrence3699 wants to merge 1 commit intosqlc-dev:mainfrom
Open
Validate unknown columns in SELECT WHERE clauses (fixes #4264)#4403lawrence3699 wants to merge 1 commit intosqlc-dev:mainfrom
lawrence3699 wants to merge 1 commit intosqlc-dev:mainfrom
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.
sqlc currently validates bad column references in SELECT targets, GROUP BY, and ORDER BY, but it lets unknown columns in SELECT WHERE clauses slip through to generated code. That means queries like
select * from "user" where is_deleted = falsepasssqlc generateeven though PostgreSQL rejects them at execution time. Fixes #4264.Run column-reference validation over SELECT WHERE clauses as well, and recurse into nested SELECTs so the same check also catches unknown columns inside EXISTS/scalar subqueries without breaking correlated references to outer scopes.
Add end-to-end fixtures for both the flat WHERE case and a nested EXISTS subquery case, with base and managed-db expectations.
Validation:
go test ./internal/endtoend -run 'TestReplay/base/invalid_where_unknown_column/postgresql/pgx$' -count=1go test ./internal/endtoend -run 'TestReplay/base/invalid_where_unknown_column_subquery/postgresql/pgx$' -count=1POSTGRESQL_SERVER_URI='postgresql://lawrence@/postgres?host=/tmp&sslmode=disable' go test ./internal/endtoend -run 'TestReplay/managed-db/invalid_where_unknown_column/postgresql/pgx$' -count=1POSTGRESQL_SERVER_URI='postgresql://lawrence@/postgres?host=/tmp&sslmode=disable' go test ./internal/endtoend -run 'TestReplay/managed-db/invalid_where_unknown_column_subquery/postgresql/pgx$' -count=1go test ./internal/endtoend -run 'TestReplay/base/select_exists/pgx/v5$' -count=1go test ./internal/endtoend -run 'TestReplay/base/select_subquery/postgresql/stdlib$' -count=1