Мне сложно по этому поводу. Я пытаюсь преобразовать varchar
, содержащий список чисел, в int array
, чтобы обслуживать оператор in
в предложении where
. Это последняя версия моего кода.
create or replace function is_product_in_categories (
_product_id integer,
_cat_list varchar
)
returns boolean
as $$
declare
_n integer;
begin
_n = 0;
select count(*)
into _n
from category_products
where product_id = _product_id and category_id in (_cat_list::int[]);
return _n > 0;
end;
$$ language plpgsql;
select is_product_in_categories(1, '1, 2, 3');
Ошибка:
SQL Error [42883]: ERROR: operator does not exist: integer = integer[]
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
Where: PL/pgSQL function is_product_in_categories(integer,character varying) line 7 at SQL statement
Я пробовал несколько аргументов, например '1, 2, 3'
, '(1, 2, 3)'
или '[1, 2, 3]'
. Также удаляем круглые скобки рядом с оператором in
, et c.
Есть идеи?