Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb8060e4

Browse files
committed
Prefer argument name over "$n" for the refname of a plpgsql argument.
If a function argument has a name, use that as the "refname" of thePLpgSQL_datum representing the argument, instead of $n as before.This allows better error messages in some cases.Pavel Stehule, reviewed by Jeevan ChalkeDiscussion:https://postgr.es/m/CAFj8pRB9GyU2U1Sb2ssgP26DZ_yq-FYDfpvUvGQ=k4R=yOPVjg@mail.gmail.com
1 parent3612019 commitb8060e4

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

‎src/pl/plpgsql/src/pl_comp.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,14 @@ do_compile(FunctionCallInfo fcinfo,
433433
errmsg("PL/pgSQL functions cannot accept type %s",
434434
format_type_be(argtypeid))));
435435

436-
/* Build variable and add to datum list */
437-
argvariable=plpgsql_build_variable(buf,0,
438-
argdtype, false);
436+
/*
437+
* Build variable and add to datum list. If there's a name
438+
* for the argument, use that as refname, else use $n name.
439+
*/
440+
argvariable=plpgsql_build_variable((argnames&&
441+
argnames[i][0]!='\0') ?
442+
argnames[i] :buf,
443+
0,argdtype, false);
439444

440445
if (argvariable->dtype==PLPGSQL_DTYPE_VAR)
441446
{

‎src/test/regress/expected/plpgsql.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6029,3 +6029,14 @@ SELECT * FROM list_partitioned_table() AS t;
60296029
2
60306030
(2 rows)
60316031

6032+
--
6033+
-- Check argument name is used instead of $n in error message
6034+
--
6035+
CREATE FUNCTION fx(x WSlot) RETURNS void AS $$
6036+
BEGIN
6037+
GET DIAGNOSTICS x = ROW_COUNT;
6038+
RETURN;
6039+
END; $$ LANGUAGE plpgsql;
6040+
ERROR: "x" is not a scalar variable
6041+
LINE 3: GET DIAGNOSTICS x = ROW_COUNT;
6042+
^

‎src/test/regress/sql/plpgsql.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4811,3 +4811,12 @@ BEGIN
48114811
END; $$ LANGUAGE plpgsql;
48124812

48134813
SELECT*FROM list_partitioned_table()AS t;
4814+
4815+
--
4816+
-- Check argument name is used instead of $n in error message
4817+
--
4818+
CREATEFUNCTIONfx(x WSlot) RETURNS voidAS $$
4819+
BEGIN
4820+
GET DIAGNOSTICS x= ROW_COUNT;
4821+
RETURN;
4822+
END; $$ LANGUAGE plpgsql;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp