Re: review: CHECK FUNCTION statement
Pavel Stehule <pavel.stehule@gmail.com>
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Albe Laurenz <laurenz.albe@wien.gv.at>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>, Tom Lane <tgl@sss.pgh.pa.us>
Date: 2011-11-30T16:06:02Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add const qualifiers to node inspection functions
- d5f23af6bfbc 9.2.0 cited
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