Skip to content

Validate unknown columns in SELECT WHERE clauses (fixes #4264)#4403

Open
lawrence3699 wants to merge 1 commit intosqlc-dev:mainfrom
lawrence3699:fix/select-where-column-validation
Open

Validate unknown columns in SELECT WHERE clauses (fixes #4264)#4403
lawrence3699 wants to merge 1 commit intosqlc-dev:mainfrom
lawrence3699:fix/select-where-column-validation

Conversation

@lawrence3699
Copy link
Copy Markdown

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 = false pass sqlc generate even 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=1
  • go test ./internal/endtoend -run 'TestReplay/base/invalid_where_unknown_column_subquery/postgresql/pgx$' -count=1
  • POSTGRESQL_SERVER_URI='postgresql://lawrence@/postgres?host=/tmp&sslmode=disable' go test ./internal/endtoend -run 'TestReplay/managed-db/invalid_where_unknown_column/postgresql/pgx$' -count=1
  • POSTGRESQL_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=1
  • go test ./internal/endtoend -run 'TestReplay/base/select_exists/pgx/v5$' -count=1
  • go test ./internal/endtoend -run 'TestReplay/base/select_subquery/postgresql/stdlib$' -count=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No error raised about obvious typo in WHERE clause

1 participant