Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

Summary

Adds a new expander package under internal/engine/postgresql/ that expands * expressions in SQL queries to explicit column names by preparing the query against a PostgreSQL database.

  • Expands SELECT * to explicit column list
  • Preserves table prefix for qualified stars (e.g., authors.*authors.id, authors.name, authors.bio)
  • Handles RETURNING * in INSERT/UPDATE/DELETE statements
  • Recursively expands CTEs, including dependent CTEs where later CTEs reference earlier ones
  • Supports subqueries in FROM clause
  • Works with both cgo (pganalyze/pg_query_go) and non-cgo (wasilibs/go-pgquery) builds

Example

-- Input
SELECT * FROM authors

-- Output
SELECT id, name, bio FROM authors
-- Input
WITH a AS (SELECT * FROM authors), b AS (SELECT * FROM a) SELECT * FROM b

-- Output
WITH a AS (SELECT id, name, bio FROM authors), b AS (SELECT id, name, bio FROM a) SELECT id, name, bio FROM b

Test plan

  • Unit tests for all supported query types
  • Tests for CTEs with dependencies
  • Tests for table-qualified stars
  • Builds with both cgo and non-cgo

🤖 Generated with Claude Code

Adds a new expander package that expands * expressions in SQL queries
to explicit column names by preparing the query against a PostgreSQL
database.

Features:
- Expands SELECT * to explicit column list
- Preserves table prefix for qualified stars (e.g., table.*)
- Handles RETURNING * in INSERT/UPDATE/DELETE statements
- Recursively expands CTEs, including dependent CTEs
- Supports subqueries in FROM clause
- Works with both cgo (pganalyze/pg_query_go) and non-cgo
  (wasilibs/go-pgquery) builds

Example:
  SELECT * FROM authors
  → SELECT id, name, bio FROM authors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants