mirror of https://github.com/postgres/postgres
plpgsql fails on new-style CREATE FUNCTION/PROCEDURE commands within a routine or DO block, because make_execsql_stmt believes that a semicolon token always terminates a SQL command. Now, that's actually been wrong since the day it was written, because CREATE RULE has long allowed multiple rule actions separated by semicolons. But there are few enough people using multi-action rules that there was never an attempt to fix it. New-style SQL functions, though, are popular. psql has this same problem of "does this semicolon really terminate the command?". It deals with CREATE RULE by counting parenthesis nesting depth: a semicolon within parens doesn't end a command. CommitsREL_16_STABLEe717a9a18
and029c5ac03
created a similar heuristic to count matching BEGIN/END pairs (but only within CREATEs, so as not to be fooled by plain BEGIN). That's survived several releases now without trouble reports, so let's just absorb those heuristics into plpgsql. Per report from Samuel Dussault. Back-patch to v14 where new-style SQL function syntax came in. Discussion: https://postgr.es/m/YT2PR01MB88552C3E9AD40A6C038774A781722@YT2PR01MB8855.CANPRD01.PROD.OUTLOOK.COM
parent
c030e263e7
commit
00f941356e
@ -0,0 +1,31 @@ |
||||
-- |
||||
-- Miscellaneous topics |
||||
-- |
||||
-- Verify that we can parse new-style CREATE FUNCTION/PROCEDURE |
||||
do |
||||
$$ |
||||
declare procedure int; -- check we still recognize non-keywords as vars |
||||
begin |
||||
create function test1() returns int |
||||
begin atomic |
||||
select 2 + 2; |
||||
end; |
||||
create or replace procedure test2(x int) |
||||
begin atomic |
||||
select x + 2; |
||||
end; |
||||
end |
||||
$$; |
||||
\sf test1 |
||||
CREATE OR REPLACE FUNCTION public.test1() |
||||
RETURNS integer |
||||
LANGUAGE sql |
||||
BEGIN ATOMIC |
||||
SELECT (2 + 2); |
||||
END |
||||
\sf test2 |
||||
CREATE OR REPLACE PROCEDURE public.test2(IN x integer) |
||||
LANGUAGE sql |
||||
BEGIN ATOMIC |
||||
SELECT (x + 2); |
||||
END |
@ -0,0 +1,22 @@ |
||||
-- |
||||
-- Miscellaneous topics |
||||
-- |
||||
|
||||
-- Verify that we can parse new-style CREATE FUNCTION/PROCEDURE |
||||
do |
||||
$$ |
||||
declare procedure int; -- check we still recognize non-keywords as vars |
||||
begin |
||||
create function test1() returns int |
||||
begin atomic |
||||
select 2 + 2; |
||||
end; |
||||
create or replace procedure test2(x int) |
||||
begin atomic |
||||
select x + 2; |
||||
end; |
||||
end |
||||
$$; |
||||
|
||||
\sf test1 |
||||
\sf test2 |
Loading…
Reference in new issue