Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: support OUT parameters in PLpgSQL UDFs #119493

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
547 changes: 540 additions & 7 deletions pkg/ccl/logictestccl/testdata/logic_test/udf_params

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/udf_plpgsql
Original file line number Diff line number Diff line change
Expand Up @@ -2900,3 +2900,11 @@ CREATE OR REPLACE FUNCTION f(x INT) RETURNS INT AS $$
$$ LANGUAGE PLpgSQL;

subtest end

statement ok
CREATE FUNCTION f_empty() RETURNS VOID AS $$ BEGIN END; $$ LANGUAGE PLpgSQL;

query T
SELECT f_empty()
----
NULL
67 changes: 67 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/udf_rewrite
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,73 @@ ALTER TYPE weekday RENAME VALUE 'humpday' TO 'wednesday';
statement ok
DROP FUNCTION f_rewrite();

statement ok
CREATE FUNCTION f_rewrite(INOUT param1 weekday, OUT param2 weekday) AS
$$
BEGIN
param2 = param1;
param1 = 'friday'::weekday;
END
$$ LANGUAGE PLPGSQL;

query T
SELECT get_body_str('f_rewrite');
----
"BEGIN\nparam2 := param1;\nparam1 := b'\\xc0':::@100107;\nEND;\n"

query TT
SHOW CREATE FUNCTION f_rewrite;
----
f_rewrite CREATE FUNCTION public.f_rewrite(INOUT param1 test.public.weekday, OUT param2 test.public.weekday)
RETURNS RECORD
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE plpgsql
AS $$
BEGIN
param2 := param1;
param1 := 'friday':::test.public.weekday;
END;
$$

statement ok
ALTER TYPE weekday RENAME VALUE 'friday' TO 'humpday';

statement ok
ALTER TYPE weekday RENAME TO workday;

query T
SELECT get_body_str('f_rewrite');
----
"BEGIN\nparam2 := param1;\nparam1 := b'\\xc0':::@100107;\nEND;\n"

query TT
SHOW CREATE FUNCTION f_rewrite;
----
f_rewrite CREATE FUNCTION public.f_rewrite(INOUT param1 test.public.workday, OUT param2 test.public.workday)
RETURNS RECORD
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE plpgsql
AS $$
BEGIN
param2 := param1;
param1 := 'humpday':::test.public.workday;
END;
$$

# Reset types for subtest.
statement ok
ALTER TYPE workday RENAME TO weekday;

statement ok
ALTER TYPE weekday RENAME VALUE 'humpday' TO 'friday';

statement ok
DROP FUNCTION f_rewrite;

subtest end

subtest rewrite_proc
Expand Down
Loading
Loading