mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +03:00
Support named and default arguments in CALL
We need to call expand_function_arguments() to expand named and default arguments. In PL/pgSQL, we also need to deal with named and default INOUT arguments when receiving the output values into variables. Author: Pavel Stehule <pavel.stehule@gmail.com>
This commit is contained in:
@ -91,6 +91,31 @@ $$;
|
||||
ERROR: calling procedures with output arguments is not supported in SQL functions
|
||||
CONTEXT: SQL function "ptest4b"
|
||||
DROP PROCEDURE ptest4a;
|
||||
-- named and default parameters
|
||||
CREATE OR REPLACE PROCEDURE ptest5(a int, b text, c int default 100)
|
||||
LANGUAGE SQL
|
||||
AS $$
|
||||
INSERT INTO cp_test VALUES(a, b);
|
||||
INSERT INTO cp_test VALUES(c, b);
|
||||
$$;
|
||||
TRUNCATE cp_test;
|
||||
CALL ptest5(10, 'Hello', 20);
|
||||
CALL ptest5(10, 'Hello');
|
||||
CALL ptest5(10, b => 'Hello');
|
||||
CALL ptest5(b => 'Hello', a => 10);
|
||||
SELECT * FROM cp_test;
|
||||
a | b
|
||||
-----+-------
|
||||
10 | Hello
|
||||
20 | Hello
|
||||
10 | Hello
|
||||
100 | Hello
|
||||
10 | Hello
|
||||
100 | Hello
|
||||
10 | Hello
|
||||
100 | Hello
|
||||
(8 rows)
|
||||
|
||||
-- various error cases
|
||||
CALL version(); -- error: not a procedure
|
||||
ERROR: version() is not a procedure
|
||||
|
@ -65,6 +65,25 @@ $$;
|
||||
DROP PROCEDURE ptest4a;
|
||||
|
||||
|
||||
-- named and default parameters
|
||||
|
||||
CREATE OR REPLACE PROCEDURE ptest5(a int, b text, c int default 100)
|
||||
LANGUAGE SQL
|
||||
AS $$
|
||||
INSERT INTO cp_test VALUES(a, b);
|
||||
INSERT INTO cp_test VALUES(c, b);
|
||||
$$;
|
||||
|
||||
TRUNCATE cp_test;
|
||||
|
||||
CALL ptest5(10, 'Hello', 20);
|
||||
CALL ptest5(10, 'Hello');
|
||||
CALL ptest5(10, b => 'Hello');
|
||||
CALL ptest5(b => 'Hello', a => 10);
|
||||
|
||||
SELECT * FROM cp_test;
|
||||
|
||||
|
||||
-- various error cases
|
||||
|
||||
CALL version(); -- error: not a procedure
|
||||
|
Reference in New Issue
Block a user