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,'[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);
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] );