postgresql: replace pg_query_go with sqlc-dev/oliphant - #4561
Merged
Conversation
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
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.
Swaps
github.com/pganalyze/pg_query_go/v6forgithub.com/sqlc-dev/oliphantv0.1.0, the pure Go drop-in replacement, as the PostgreSQL SQL parser.Changes
internal/engine/postgresql/{parse,convert,utils}.goimportgithub.com/sqlc-dev/oliphant(andoliphant/parserfor theErrortype) in place ofpg_query_go/v6.parse_default.go,parse_wasi.go, and the engine'sparseralias package are deleted, and thewasilibs/go-pgqueryfallback 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:
RETURNINGlists into aReturningClausemessage, renamedRowCompareExpr.rctypetocmptype, and typedIntoClause.view_queryasQuery.stmt_locationto 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 — soParseconverts back, including reporting an unterminated final statement as zero-length to preserve themissing semicolon at end of fileerror.Testing
go test --tags=examples -timeout 20m ./...) passes with live PostgreSQL and MySQL.TestReplay/corecontext 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