E
E
er122015-09-05 17:38:37
MySQL
er12, 2015-09-05 17:38:37

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;

The function returns nothing if age=33.6
Please tell me what could be wrong

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2015-09-05
@rostel

the FOREACH loop is not executed, you
can verify by replacing
and call with age=33.6

V
veliks1, 2015-09-09
@veliks1

Maybe  without age?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question