fix(plpgsql-deparser): cursor SCROLL options, FETCH/MOVE directions, SQLSTATE conditions, bare RAISE, subscripted assignment targets#303
Merged
pyramation merged 1 commit intoJul 20, 2026
Conversation
…SQLSTATE conditions, bare RAISE, subscripted assignment targets
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Five round-trip corruption bugs found by fuzzing the deparser with esoteric PL/pgSQL (all outputs now reparse AND deploy against a real PG 18):
deparseOpentestedcursor_options & 256/512(those areCURSOR_OPT_FAST_PLAN/GENERIC_PLAN, which plpgsql always sets), so everyOPEN c;became invalidOPEN SCROLL c;. Correct masks are0x2/0x4, SCROLL goes after the cursor name, and only for unboundOPEN ... FOR— a bound cursor's option belongs on its declaration.deparseVarnever emitted it; nowc SCROLL CURSOR FOR .../NO SCROLLround-trip.FORWARD n/BACKWARD ncounts are stored as anexprthe direction printer ignored (MOVE FORWARD 3→MOVE);ALLishow_many = INT_MAX, not 0; andFIRST/LAST(ABSOLUTE ±1 with no expr) now print asFIRST/LASTso the reparse AST matches.WHEN SQLSTATE '23503'deparsed as invalidWHEN 23503— condnames matching/^[0-9A-Z]{5}$/(named conditions are lowercase identifiers) are re-emitted asSQLSTATE 'xxxxx'.RAISE;deparsed as invalidRAISE EXCEPTION;— a raise with no condname/message/options is now emitted bare.a[2] := 20deparsed as invalid(a)[2] := 20— the SQL deparser parenthesizesA_Indirectiontargets, but the plpgsql assignment grammar requires a bare identifier;deparseAssignunwraps a leading(ident)before[/..Fixtures: Tests 47–53 in
__fixtures__/plpgsql/plpgsql_deparser_fixes.sql(regeneratedgenerated.jsonviapnpm fixtures), plus explicit snapshot tests indeparser-fixes.test.ts. Existing snapshot changes are allRAISE EXCEPTION;→RAISE;(fix #5). Full workspace suite passes.Link to Devin session: https://app.devin.ai/sessions/eeb8deba0c04475091df703c88877302
Requested by: @pyramation