Skip to content

Keep LANGUAGE C library and symbol names unchanged in CREATE FUNCTION - #420

Open
youdie006 wants to merge 1 commit into
darold:masterfrom
youdie006:c-function-library-path
Open

youdie006 wants to merge 1 commit into
darold:masterfrom
youdie006:c-function-library-path

Conversation

@youdie006

Copy link
Copy Markdown

Since SQL function bodies are formatted (eaa0529), the string after AS in a LANGUAGE C function is reformatted as SQL:

CREATE FUNCTION f() RETURNS bool AS '$libdir/foo', 'bar' LANGUAGE C;
-- formatted: AS '\n    $ libdir / foo;\n\n', 'bar'

and AS 'MODULE_PATHNAME' becomes '\n MODULE_PATHNAME;\n', which changes the library PostgreSQL loads. The C branch in _pre_process that should hide these strings never matched: it had no single-string form, and the link symbol had already been replaced by an AAKEYWCONST placeholder. It now accepts both forms, so the strings are kept verbatim with LANGUAGE before or after AS.

expected/ex61.sql goes back to its output before the regression (identical to 0707b83), and the new ex90 covers both C forms plus a LANGUAGE sql body that is still formatted. Formatting contrib hstore 1.4 now leaves all 57 C function definitions with the same parse tree (checked with pglast). prove -l t/ and t/regress_test.pl pass. This also bumps t/02_regress.t to 91, like #418 and #419, so whichever lands later needs the count adjusted.

Single-quoted bodies of other non-SQL languages are also formatted (AS 'return 1;' LANGUAGE plperl becomes RETURN 1;); I left that out here and can send it separately if you want it handled.

Written with AI assistance (Claude); I have reviewed the change.

The C branch in _pre_process never matched: it had no single-string
form, and the link symbol had already been replaced by an AAKEYWCONST
placeholder. Since SQL function bodies are formatted, the strings were
then reformatted as SQL, changing the library PostgreSQL loads.
@AndrewJackson2020

Copy link
Copy Markdown

I have not reviewed this patch but +1 fixing this. Would love to incorporate pgformatter into extension CI pipelines to enforce formatting but am not able to because of this issue.

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.

2 participants