Skip to content

Add MemoryToken::parse - #45

Merged
sgrif merged 1 commit into
mainfrom
sg-make-parse
Aug 5, 2026
Merged

Add MemoryToken::parse#45
sgrif merged 1 commit into
mainfrom
sg-make-parse

Conversation

@sgrif

@sgrif sgrif commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Currently if you want to manipulate a query immediately after parsing it, you have to call pg_raw_parse::parse, then
MemoryToken::make_unique to perform a deep copy onto a new memory context. We have places in pgdog which are using this pattern, and immediately throwing away the unmodified AST/MemoryContext. We can skip the extra copy/allocation by allowing you to parse within make::try_owned directly.

We ended up never actually exposing the warnings field of ParseResult, so I've gone ahead and removed it entirely. If we do ever want to expose them, I'll either need to change the signature of parse to return them as well as the stmts, or provide a new function that returns both.

At this point ParseResult is a pointless type and can be removed, but doing so is an API breaking change so I've left it in for now.

Currently if you want to manipulate a query immediately after parsing
it, you have to call `pg_raw_parse::parse`, then
`MemoryToken::make_unique` to perform a deep copy onto a new memory
context. We have places in `pgdog` which are using this pattern, and
immediately throwing away the unmodified AST/MemoryContext. We can skip
the extra copy/allocation by allowing you to parse within `make::try_owned`
directly.

We ended up never actually exposing the `warnings` field of
`ParseResult`, so I've gone ahead and removed it entirely. If we do ever
want to expose them, I'll either need to change the signature of `parse`
to return them as well as the stmts, or provide a new function that
returns both.

At this point `ParseResult` is a pointless type and can be removed, but
doing so is an API breaking change so I've left it in for now.
@sgrif
sgrif requested review from levkk and meskill August 4, 2026 20:30
@sgrif
sgrif merged commit 273d16b into main Aug 5, 2026
1 check passed
@sgrif
sgrif deleted the sg-make-parse branch August 5, 2026 11:47
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