The plpgsql function:
CREATE OR REPLACE FUNCTION testarray (int[]) returns int as $$
DECLARE
len int;
BEGIN
len := array_upper($1);
return len;
END
$$ language plpgsql;
The node-postgres query + test array:
var ta = [1,2,3,4,5];
client.query('SELECT testarray($1)', [ta], function(err, result) {
console.log('err: ' + err);
console.log('result: ' + result);
});
Output from node server:
err: error: array value must start with "{" or dimension information
result: undefined
I also tried cast the parameter in the client query like testarray($1::int[])
which returned the same error.
I changed the function argument to (anyarray int)
and the output error changed:
err: error: invalid input syntax for integer: "1,2,3,4,5"
result: undefined
As well as a couple other variations.
I seek the variation that produces no error and returns 5.
I read about the Postgres parse-array issue and this stackoverflow question on parameterised arrays in node-postgres:
But the answer didn't seem to be there.