I would like to update a selection of rows in a table; this works...
UPDATE t1 SET col1 = 'newvalue' WHERE col0 in (2, 4, 5);
But how can I do the same in a plpgsql function? The following gives a syntax error...
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;
The error...
ERROR: syntax error at or near "intarray"
LINE 7: WHERE col0 in intarray;
Edit:
If we replace in intarray;
with in (intarray);
the function is recorded but when running SELECT * FROM foo(ARRAY[1,3,5])
the error becomes...
ERROR: operator does not exist: integer = integer[]
LINE 2: WHERE col0 in (intarray)
WHERE col0 = ANY (intarray)