Repository navigation
Return errors for PL/pgSQL statements without bodies (cherry-pick of upstream #363) - #14
Open
pyramation wants to merge 1 commit into
Open
pyramation wants to merge 1 commit into
pyramation wants to merge 1 commit into
Conversation
* Fix PL/pgSQL parsing without function bodies Return PostgreSQL errors when CREATE FUNCTION or DO omits its AS clause instead of asserting or dereferencing a null source pointer in release builds. Add regression coverage for both malformed statement types. Fixes pganalyze#362. * Skip non-PL/pgSQL functions before checking for a body, add more checks Check the language before requiring an AS clause, so that valid SQL-standard function bodies (LANGUAGE sql RETURN ... / BEGIN ATOMIC) are skipped as before instead of returning an error. For PL/pgSQL functions, also raise upstream's "duplicate function body specified" and "inline SQL function body only valid for language SQL" errors, as in Postgres' interpret_AS_clause function. In passing, fix a related memory leak for raw parser's stderr buffer when the input contains no CREATE FUNCTION or DO statements, which previously leaked. --------- Co-authored-by: Darren Carreras <283775510+carrerasdarren-cell@users.noreply.github.com> Co-authored-by: Lukas Fittl <lukas@fittl.com> (cherry picked from commit e275398)
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
The PR ports upstream
Reviewed commit: 99174d9 |
|
Folded into #13 |
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
pg_query_parse_plpgsqlaborted withassert(proc_source != NULL)on anyCREATE FUNCTION/PROCEDUREwithout anASclause. That includes valid SQL-standard bodies:In the WASM build (libpg-query 18.x
parsePlPgSQL) this surfaces asRuntimeError: Aborted(Assertion failed: proc_source != NULL …).This is a clean cherry-pick (
-x) of upstream e275398 (pganalyze#363):compile_create_function_stmt_via_callbackchecks the language first. Non-PL/pgSQL functions are skipped as before (palloc0function), soLANGUAGE sql … BEGIN ATOMICreturns a result.interpret_AS_clauseerrors:no function body specified/duplicate function body specified.compile_do_stmtraisesno inline code specifiedinstead of asserting.test/parse_plpgsql.c.17-constructive has the same two asserts, but libpg-query 17 doesn't export
parsePlPgSQL, so this PR only targets 18.CI: every build passes, local
make testpasses. Thevalgrindjobs fail only ontest/parse_plpgsql, with the 192-byte still-reachable block frompg_query_plpgsql_record_alias(pg_query_json_plpgsql.c:826). That failure is not caused by this PR:The node pin is left to the combined fork/node PR.
Link to Devin session: https://app.devin.ai/sessions/b32426e30a71409594f003cf94c9e560
Open in Devin Desktop: https://app.devin.ai/desktop/session/b32426e30a71409594f003cf94c9e560?variant=devin
Requested by: @pyramation