我想在 postgresql 上创建一个函数,该函数接收一个 bigint 数组(记录 id),并使用“in”条件在查询中使用接收到的信息。
我知道我可以自己简单地进行查询,但这里的重点是我将创建将执行一些其他验证和过程的函数。
我试图使用的来源是这样的:
CREATE OR REPLACE FUNCTION func_test(VARIADIC arr bigint[])
RETURNS TABLE(record_id bigint,parent_id bigint)
AS $$ SELECT s.record_id, s.parent_id FROM TABLE s WHERE s.column in ($1);
$$ LANGUAGE SQL;
使用上面的代码,我收到以下错误:
ERROR: operator does not exist: bigint = bigint[]
LINE 3: ...ECT s.record_id, s.parent_id FROM TABLE s WHERE s.column in ($1)
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
我怎样才能解决这个问题?