Обсуждение: Function syntax checking

Поиск
Список
Период
Сортировка

Function syntax checking

От
Karim Nassar
Дата:
I am writing functions and I find it curious that CREATE FUNCTION does
not do syntax checking.

Example:

test=# CREATE FUNCTION foo(INTEGER) RETURNS BOOLEAN
test-# AS 'this is total crap' LANGUAGE plpgsql;
CREATE FUNCTION
test=# select foo(1);
ERROR:  syntax error at or near "this"
CONTEXT:  compile of PL/pgSQL function "foo" near line 1

The statement itself is valid, but the function causes runtime syntax
errors. Seems like one could run the interpreter with bogus, but
syntactically correct arguments to the function, creating the
instruction tree. Then run through the tree and try to create execution
plans for all the statements. The cost of this would be well worth *my*
time ;-)

Is there a technical reason this doesn't happen?

TIA,
\<.



Re: Function syntax checking

От
Tom Lane
Дата:
Karim Nassar <Karim.Nassar@NAU.EDU> writes:
> I am writing functions and I find it curious that CREATE FUNCTION does
> not do syntax checking.

Try 8.0 ;-)

regression=# CREATE FUNCTION foo(INTEGER) RETURNS BOOLEAN
regression-# AS 'this is total crap' LANGUAGE plpgsql;
ERROR:  syntax error at or near "this" at character 50
LINE 2: AS 'this is total crap' LANGUAGE plpgsql;
            ^

We could be doing more along this line, but it's a start ...

            regards, tom lane