fix(plpgsql-deparser): bound cursor argument lists and RAISE SQLSTATE conditions#306
Merged
Merged
Conversation
… conditions - Bound cursors with explicit args (c CURSOR (key int) FOR ...) lost their parameter list on deparse: the args leaked out as standalone DECLARE variables and OPEN c(42) then failed to re-parse against a no-arg cursor. Reconstruct the parameter list from cursor_explicit_argrow and suppress the arg vars from the DECLARE section. - RAISE SQLSTATE '22012' deparsed as RAISE EXCEPTION 22012 (invalid syntax). Emit 5-char condition codes as SQLSTATE literals, matching the existing exception-handler condition logic.
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
Two more round-trip corruption bugs found by sweeping esoteric PL/pgSQL shapes through the downstream round-trip harness — both produced SQL that fails to re-parse:
1. Bound cursors with explicit arguments lost their parameter list.
deparseVarnow reconstructs the parameter list fromcursor_explicit_argrow(thePLpgSQL_rowwhosefields[].varnopoint at the arg var datums), anddeparseDeclareSectionsuppresses those arg vars from standalone DECLARE output.2.
RAISE SQLSTATE 'xxxxx'deparsed asRAISE EXCEPTION 22012— a syntax error. Condition codes matching/^[0-9A-Z]{5}$/are now emitted asSQLSTATE '22012', mirroring the existing exception-handler condition logic; named conditions (RAISE EXCEPTION division_by_zero) are unchanged.Fixtures: Tests 54–56 added to
plpgsql_deparser_fixes.sql(+ regeneratedgenerated.json), plus explicit snapshot tests. 104/104 tests pass.Link to Devin session: https://app.devin.ai/sessions/eeb8deba0c04475091df703c88877302
Requested by: @pyramation