Re: review: CHECK FUNCTION statement - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: review: CHECK FUNCTION statement
Date
Msg-id CAFj8pRA4JzNw=0scspB0F7qY2JOAXWg0HBKM7dhxKKEtRLomEg@mail.gmail.com
Whole thread Raw
In response to Re: review: CHECK FUNCTION statement  ("Albe Laurenz" <laurenz.albe@wien.gv.at>)
List 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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: review: CHECK FUNCTION statement
Next
From: Robert Haas
Date:
Subject: Re: review: CHECK FUNCTION statement