Skip to content

fix: resolve OUT-param varno by signature names for bare RETURN#311

Merged
pyramation merged 2 commits into
mainfrom
fix/out-param-varno-resolution
Jul 21, 2026
Merged

fix: resolve OUT-param varno by signature names for bare RETURN#311
pyramation merged 2 commits into
mainfrom
fix/out-param-varno-resolution

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

Fixes invalid SQL emitted for bare RETURN; in functions with OUT parameters. libpg-query@18 never serializes PLpgSQL_function.out_param_varno, so when the single OUT param is not datum 0 (i.e. IN params precede it), resolveOutParamVarno failed and the deparser rendered the compiler's retvarno as RETURN <out_param>; — which PostgreSQL rejects (RETURN cannot have a parameter in function with OUT parameters). This broke constructive-db's generate pipeline for functions like:

CREATE FUNCTION f(a text, b uuid, OUT result uuid) RETURNS uuid AS $$
BEGIN ... RETURN;  -- was deparsed as: RETURN result;
END$$ LANGUAGE plpgsql;

Changes:

  • ReturnInfo gains outParamNames?: string[]; getReturnInfo (plpgsql-parser) populates it from FunctionParameter modes (OUT/INOUT/TABLE).
  • resolveOutParamVarno first resolves by name: single OUT name → matching PLpgSQL_var datum index; multiple OUT names → the (unnamed row) datum whose fields match the names. Existing heuristics kept as fallback.
  • plpgsql-deparser test harness now derives ReturnInfo from the fixture's CREATE FUNCTION signature (deriveReturnInfo), matching how plpgsql-parser's transform pipeline deparses.
  • New fixtures: bare RETURN with single non-first OUT param and with multiple OUT params.

All suites green: plpgsql-deparser 106, plpgsql-parser 292, plpgsql-parse 57, parse 68. Verified against the 5 constructive-db functions that failed round-trip in its generate CI.

Link to Devin session: https://app.devin.ai/sessions/064ad193e1c040af8c145d55e07af9b8
Requested by: @pyramation

@pyramation pyramation self-assigned this Jul 21, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedlibpg-query@​18.1.210010010096100

View full report

@pyramation
pyramation merged commit a67fb33 into main Jul 21, 2026
9 checks passed
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.

1 participant