Postgresql 错误:运算符不存在:整数integer[]
我试图创建一个函数,其中我传递一个数组作为参数 当我尝试执行该函数时,出现以下错误:Postgresql 错误:运算符不存在:整数integer[],postgresql,Postgresql,我试图创建一个函数,其中我传递一个数组作为参数 当我尝试执行该函数时,出现以下错误: [2020-12-07 13:53:58] [42883] ERROR: operator does not exist: integer <> integer[] [2020-12-07 13:53:58] Hint: No operator matches the given name and argument types. You might need to add explicit type
[2020-12-07 13:53:58] [42883] ERROR: operator does not exist: integer <> integer[]
[2020-12-07 13:53:58] Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
[2020-12-07 13:53:58] Where: PL/pgSQL function vectors_paginated(uuid,text,integer[]) line 16 at IF
我做错了什么?不在不能与数组一起使用,您需要使用vector.actor\u键入所有actors
但我认为,通过将条件放在WHERE中,并摆脱缓慢而低效的逐行处理,可以大大简化整个功能:
CREATE OR REPLACE FUNCTION vectors_paginated(analysisId uuid, vectorName text, actors int[])
RETURNS SETOF vectors
AS
$$
SELECT aiv.*
FROM vectors AS aiv
WHERE aiv.analysis_id = analysisId
AND (vectorName is NULL OR Lower(aiv.name) NOT LIKE '%' || Lower(vectorName) || '%')
AND (actors IS NULL OR aiv.actor_type <> ALL (actors));
$$
language SQL;
您向我们展示的代码中没有任何内容。这是我拥有的完整脚本。我假设它与我传递参数的方式有关,我添加了其余的参数
CREATE OR REPLACE FUNCTION vectors_paginated(analysisId uuid, vectorName text, actors int[])
RETURNS SETOF vectors
AS
$$
SELECT aiv.*
FROM vectors AS aiv
WHERE aiv.analysis_id = analysisId
AND (vectorName is NULL OR Lower(aiv.name) NOT LIKE '%' || Lower(vectorName) || '%')
AND (actors IS NULL OR aiv.actor_type <> ALL (actors));
$$
language SQL;