我有一个用 plpythonu 编写的函数。
CREATE OR REPLACE FUNCTION temp(t_x integer[])
RETURNS void AS
$BODY$
.
.
.
x=plpy.execute("""select array_to_string(select id from A where id=any(array%s) ), ',')"""%t_x)
Run Code Online (Sandbox Code Playgroud)
在某些情况下,当 t_x 为空时,我会收到错误消息:
错误:无法确定空数组的类型
我如何解决它?
伪代码:
if t_x is empty
x=null
else
x=plpy.execute....
Run Code Online (Sandbox Code Playgroud)
x=plpy.execute("""select array_to_string(select id from A where id=any(array%s::integer[]) ), ',')"""%t_x)
Run Code Online (Sandbox Code Playgroud)
为什么要投帮助?
postgres=# select pg_typeof(array[1,2]);
pg_typeof
-----------
integer[]
Run Code Online (Sandbox Code Playgroud)
array[1,2] 有类型 integer[]
postgres=# select array[];
ERROR: cannot determine type of empty array
LINE 1: select array[];
Run Code Online (Sandbox Code Playgroud)
array[] 没有类型。
postgres=# select pg_typeof(array[]::integer[]);
pg_typeof
-----------
integer[]
Run Code Online (Sandbox Code Playgroud)
array[]::integer[] 有类型 integer[]