Answer the question
In order to leave comments, you need to log in
Where is the error in the sql function?
CREATE OR REPLACE FUNCTION disp.test( tt integer, age character varying ) RETURNS boolean AS
$$
DECLARE
x numeric;
num character varying;
model_age text [] ;
xage numeric;
actual_patient boolean;
BEGIN
actual_patient=false;
model_age=(select array_agg(mmpb.age::text) ));-- в результате запроса данные ввида ["23,45,33", "2.0,67"]
xage:=age::NUMERIC;
if xage>=3 then xage:=trunc(xage); end if;
if model_age is not null then
FOREACH num IN ARRAY regexp_split_to_array(model_age, ',')
LOOP
x:=num::NUMERIC;
if xage=x then actual_patient:=true; exit; end if;
END LOOP;
return actual_patient;
else return actual_patient; end if;
EXCEPTION WHEN others THEN
return trim(num);
END;
$$
LANGUAGE plpgsql VOLATILE
COST 100;
Answer the question
In order to leave comments, you need to log in
the FOREACH loop is not executed, you
can verify by replacing
and call with age=33.6
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question