The query inside the public.fnGetEmailUsuarios( ids int[] )
function has an error in its WHERE
clause.
The IN()
operator expects a list of scalar values
and its function is passing an argument of type IN()
to array
.
You need operators capable of receiving values of type array
, such as SOME()
or ANY()
.
Assuming you have something like:
CREATE TABLE public.usuario
(
id INTEGER,
email VARCHAR(40),
tipo INTEGER
);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (1,'[email protected]', 10);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (2,'[email protected]', 20);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (3,'[email protected]', 30);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (4,'[email protected]', 40);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (5,'[email protected]', 50);
Your function should be rewritten as follows in order to work correctly:
CREATE OR REPLACE FUNCTION public.fnGetEmailUsuarios(ids int[])
RETURNS TABLE(email VARCHAR(40))
AS $BODY$
BEGIN
RETURN QUERY SELECT u.email FROM public.usuario u WHERE u.tipo = ANY ( ids );
END;
$BODY$ LANGUAGE plpgsql;
What would make queries of the type:
SELECT public.fnGetEmailUsuarios( ARRAY[10,30,50] );