mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-01 14:31:18 +02:00
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 the PLpgSQL_datum representing the argument, instead of $n as before. This allows better error messages in some cases. Pavel Stehule, reviewed by Jeevan Chalke Discussion: https://postgr.es/m/CAFj8pRB9GyU2U1Sb2ssgP26DZ_yq-FYDfpvUvGQ=k4R=yOPVjg@mail.gmail.com
This commit is contained in:
parent
3612019a79
commit
b8060e41b5
@ -433,9 +433,14 @@ do_compile(FunctionCallInfo fcinfo,
|
|||||||
errmsg("PL/pgSQL functions cannot accept type %s",
|
errmsg("PL/pgSQL functions cannot accept type %s",
|
||||||
format_type_be(argtypeid))));
|
format_type_be(argtypeid))));
|
||||||
|
|
||||||
/* Build variable and add to datum list */
|
/*
|
||||||
argvariable = plpgsql_build_variable(buf, 0,
|
* Build variable and add to datum list. If there's a name
|
||||||
argdtype, false);
|
* for the argument, use that as refname, else use $n name.
|
||||||
|
*/
|
||||||
|
argvariable = plpgsql_build_variable((argnames &&
|
||||||
|
argnames[i][0] != '\0') ?
|
||||||
|
argnames[i] : buf,
|
||||||
|
0, argdtype, false);
|
||||||
|
|
||||||
if (argvariable->dtype == PLPGSQL_DTYPE_VAR)
|
if (argvariable->dtype == PLPGSQL_DTYPE_VAR)
|
||||||
{
|
{
|
||||||
|
@ -6029,3 +6029,14 @@ SELECT * FROM list_partitioned_table() AS t;
|
|||||||
2
|
2
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Check argument name is used instead of $n in error message
|
||||||
|
--
|
||||||
|
CREATE FUNCTION fx(x WSlot) RETURNS void AS $$
|
||||||
|
BEGIN
|
||||||
|
GET DIAGNOSTICS x = ROW_COUNT;
|
||||||
|
RETURN;
|
||||||
|
END; $$ LANGUAGE plpgsql;
|
||||||
|
ERROR: "x" is not a scalar variable
|
||||||
|
LINE 3: GET DIAGNOSTICS x = ROW_COUNT;
|
||||||
|
^
|
||||||
|
@ -4811,3 +4811,12 @@ BEGIN
|
|||||||
END; $$ LANGUAGE plpgsql;
|
END; $$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
SELECT * FROM list_partitioned_table() AS t;
|
SELECT * FROM list_partitioned_table() AS t;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Check argument name is used instead of $n in error message
|
||||||
|
--
|
||||||
|
CREATE FUNCTION fx(x WSlot) RETURNS void AS $$
|
||||||
|
BEGIN
|
||||||
|
GET DIAGNOSTICS x = ROW_COUNT;
|
||||||
|
RETURN;
|
||||||
|
END; $$ LANGUAGE plpgsql;
|
||||||
|
Loading…
Reference in New Issue
Block a user