问题描述
我正在尝试使用PostgreSQL数据库维护Php应用程序.在某一时刻,调用了一个存储过程,比如说function_x
,并且在function_x
内部,调用了function_y
. function_y
传递了一个名为parameter_1
的变量,而parameter_1的定义为:
I'm trying to maintain a Php application with a PostgreSQL database. At one point, a stored procedure is called, lets say function_x
and inside function_x
, function_y
is called; function_y
is passed a variable named parameter_1
, and the definition of parameter_1 is:
parameter_1 numeric[][3] := {};
我正在尝试直接在命令行(或pgadmin)上执行select function_y,但是在将空数组传递给函数时遇到了问题.根据 docs ,您必须使用variadic
,但是我试过了:
I'm trying to do a select function_y directly on the command line (or pgadmin) but I'm having problems passing an empty array into the function. according to the docs you have to use variadic
but so I tried:
select function_y(581, 'CPN-00000000001-0000', 'TPN-00000000001-0001', 100, 2013, variadic arr := array[]);
但是我得到了这个错误:
But I got this error:
ERROR: cannot determine type of empty array
我尝试了不同的方法,但是没有任何效果.如何在查询中将多维数组作为参数传递?
I tried different approaches but nothing works. How can I pass a multidimensional array as a parameter at a query?
推荐答案
1)您可以,但您不必使用 VARIADIC
参数用于数组变量.不过,您必须在函数的声明中使用它,而不是在调用中使用它.
1) You can, but you do not have to use VARIADIC
parameters for array variables. You'd have to use it in the declaration of the function, not in the call, though.
2)Postgres数组变量忽略定义中的尺寸.我引用了此处的手册:
2) Postgres array variables ignore dimensions in the definition. I quote the manual here:
3)这是无效的语法:
3) This is invalid syntax:
需要单引号
parameter_1 numeric[][3] := '{}';
实际上与
parameter_1 numeric[] := '{}';
与此紧密相关的答案中的更多详细信息,代码示例和链接:
返回行匹配plpgsql函数中输入数组的元素
More details, code examples and links in this closely related answer:
Return rows matching elements of input array in plpgsql function
这篇关于将多维数组作为参数传递给Postgresql函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!