From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Subject: | Re: review: CHECK FUNCTION statement |
Date: | 2011-11-30 16:06:02 |
Message-ID: | CAFj8pRA4JzNw=0scspB0F7qY2JOAXWg0HBKM7dhxKKEtRLomEg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello
>
> CREATE OR REPLACE FUNCTION t(i integer) RETURNS integer
> LANGUAGE plpgsql STRICT AS
> $$DECLARE j integer;
> BEGIN
> IF i=1 THEN
> FOR I IN 1..4 BY -1 LOOP
> RAISE NOTICE '%', i;
> END LOOP;
> RETURN -1;
> ELSE
> RETURN 2*i;
> END IF;
> END;$$;
>
> CHECK FUNCTION t(integer); -- no error
>
> SELECT t(1);
> ERROR: BY value of FOR loop must be greater than zero
> CONTEXT: PL/pgSQL function "t" line 4 at FOR with integer loop variable
>
> 2)
>
> CREATE OR REPLACE FUNCTION t(i integer) RETURNS integer
> LANGUAGE plpgsql STRICT AS
> $$DECLARE j integer;
> BEGIN
> IF i=1 THEN
> j=9999999999999999999;
> RETURN j;
> ELSE
> RETURN 2*i;
> END IF;
> END;$$;
>
> CHECK FUNCTION t(integer); -- no error
>
> SELECT t(1);
> ERROR: value "9999999999999999999" is out of range for type integer
> CONTEXT: PL/pgSQL function "t" line 4 at assignment
>
This kind of check are little bit difficult. It is solveable but I
would to have a skelet in core, and then this skelet can be enhanced
step by step.
Where is problem? PL/pgSQL usually don't work with numeric constant.
Almost all numbers are expressions - and checking function ensure only
semantic validity of expression, but don't try to evaluate expression.
So isn't possible to check runtime errors now.
Regards
Pavel
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2011-11-30 16:09:13 | Re: review: CHECK FUNCTION statement |
Previous Message | Robert Haas | 2011-11-30 16:03:59 | Re: review: CHECK FUNCTION statement |