Consultation within the function public.fnGetEmailUsuarios( ids int[] )
has an error in its clause WHERE
.
The operator IN()
expects a list of scalar values
and its function is passing to IN()
an argument of the kind array
.
You need operators capable of receiving type values 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,'alpha@teste.com', 10);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (2,'beta@teste.com', 20);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (3,'gamma@teste.com', 30);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (4,'delta@teste.com', 40);
INSERT INTO public.usuario ( id, email, tipo ) VALUES (5,'episilon@teste.com', 50);
Its function must be rewritten as follows in order to function 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 allow consultations of the type:
SELECT public.fnGetEmailUsuarios( ARRAY[10,30,50] );