我想更新表中的行选择;这有效...
UPDATE t1 SET col1 = 'newvalue' WHERE col0 in (2, 4, 5);
Run Code Online (Sandbox Code Playgroud)
但是我怎么能在 plpgsql 函数中做同样的事情呢?下面给出了一个语法错误...
CREATE OR REPLACE FUNCTION foo(intarray int[])
RETURNS VOID AS
$BODY$
BEGIN
UPDATE t1 SET col1 = 'newvalue'
WHERE col0 in intarray;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
Run Code Online (Sandbox Code Playgroud)
错误...
ERROR: syntax error at or near "intarray"
LINE 7: WHERE col0 in intarray;
Run Code Online (Sandbox Code Playgroud)
编辑:
如果我们更换in intarray;
用in (intarray);
的功能被记录,但在运行时SELECT * FROM foo(ARRAY[1,3,5])
的误差变...
ERROR: operator does not exist: integer = integer[]
LINE 2: WHERE …
Run Code Online (Sandbox Code Playgroud)