Skip to content

postgresql: replace pg_query_go with sqlc-dev/oliphant - #4561

Merged
kyleconroy merged 2 commits into
mainfrom
claude/oliphant-lib-query-alias-gpuadi
Aug 17, 2026
Merged

postgresql: replace pg_query_go with sqlc-dev/oliphant#4561
kyleconroy merged 2 commits into
mainfrom
claude/oliphant-lib-query-alias-gpuadi

Conversation

@kyleconroy

@kyleconroy kyleconroy commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Swaps github.com/pganalyze/pg_query_go/v6 for github.com/sqlc-dev/oliphant v0.1.0, the pure Go drop-in replacement, as the PostgreSQL SQL parser.

Changes

  • internal/engine/postgresql/{parse,convert,utils}.go import github.com/sqlc-dev/oliphant (and oliphant/parser for the Error type) in place of pg_query_go/v6.
  • Since oliphant needs neither cgo nor wasm, the cgo/wasi build-tag split collapses: parse_default.go, parse_wasi.go, and the engine's parser alias package are deleted, and the wasilibs/go-pgquery fallback dependency is dropped. Windows and non-cgo builds now use the same parser as everything else.

Beyond the alias

Oliphant tracks libpg_query 18 while sqlc was on the 17-era protobuf, so two adaptations were needed:

  • convert.go (5 sites): PostgreSQL 18 moved RETURNING lists into a ReturningClause message, renamed RowCompareExpr.rctype to cmptype, and typed IntoClause.view_query as Query.
  • parse.go: PostgreSQL 18 changed stmt_location to point at a statement's first token instead of the end of the previous statement. The compiler depends on the old convention — a statement's span is what carries its leading -- name: comment — so Parse converts back, including reporting an unterminated final statement as zero-length to preserve the missing semicolon at end of file error.

Testing

  • Full suite (go test --tags=examples -timeout 20m ./...) passes with live PostgreSQL and MySQL.
  • The opt-in TestReplay/core context has 527 failing cases both before and after this change — verified the failure sets are identical, so these are the known pre-existing core-analyzer disagreements, not regressions.

🤖 Generated with Claude Code

https://claude.ai/code/session_01F4xWkw3nC1NQdjfNm8Mgyt

claude added 2 commits August 17, 2026 16:18
Swap github.com/pganalyze/pg_query_go/v6 for github.com/sqlc-dev/oliphant,
a pure Go drop-in replacement with the same API. Since it needs neither cgo
nor wasm, the cgo/wasi build-tag split collapses: parse_default.go,
parse_wasi.go and the engine's parser alias package are gone, along with
the wasilibs/go-pgquery fallback dependency.

Oliphant tracks libpg_query 18, which moved RETURNING lists into a
ReturningClause message, renamed RowCompareExpr.rctype to cmptype, typed
IntoClause.view_query as Query, and changed stmt_location to point at a
statement's first token instead of the end of the previous statement.
convert.go adapts to the new shapes, and Parse restores the pre-18
location convention the compiler expects, so statements keep carrying
their leading '-- name:' comments and an unterminated final statement is
still reported via a zero length.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F4xWkw3nC1NQdjfNm8Mgyt
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F4xWkw3nC1NQdjfNm8Mgyt
@kyleconroy
kyleconroy merged commit 2e0f745 into main Aug 17, 2026
13 checks passed
@kyleconroy
kyleconroy deleted the claude/oliphant-lib-query-alias-gpuadi branch August 17, 2026 17:58
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