Add MemoryToken::parse - #45
Merged
Merged
Conversation
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.
meskill
approved these changes
Aug 5, 2026
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.
Currently if you want to manipulate a query immediately after parsing it, you have to call
pg_raw_parse::parse, thenMemoryToken::make_uniqueto perform a deep copy onto a new memory context. We have places inpgdogwhich are using this pattern, and immediately throwing away the unmodified AST/MemoryContext. We can skip the extra copy/allocation by allowing you to parse withinmake::try_owneddirectly.We ended up never actually exposing the
warningsfield ofParseResult, 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 ofparseto return them as well as the stmts, or provide a new function that returns both.At this point
ParseResultis a pointless type and can be removed, but doing so is an API breaking change so I've left it in for now.