1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-07 12:02:30 +03:00

Add optional "validator" function to languages that can validate the

function body (and other properties) as a function in the language
is created.  This generalizes ad hoc code that already existed for
the built-in languages.

The validation now happens after the pg_proc tuple of the new function
is created, so it is possible to define recursive SQL functions.

Add some regression test cases that cover bogus function definition
attempts.
This commit is contained in:
Peter Eisentraut
2002-05-22 17:21:02 +00:00
parent df9c8e1a39
commit d60f10b0e7
18 changed files with 339 additions and 102 deletions

View File

@@ -42,3 +42,28 @@ CREATE FUNCTION set_ttdummy (int4)
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'C';
-- Things that shouldn't work:
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT ''not an integer'';';
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'not even SQL';
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT 1, 2, 3;';
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT $2;';
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'a', 'b';
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE c
AS 'nosuchfile';
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE c
AS '@abs_builddir@/regress@DLSUFFIX@', 'nosuchsymbol';
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE internal
AS 'nosuch';

View File

@@ -34,3 +34,28 @@ CREATE FUNCTION set_ttdummy (int4)
RETURNS int4
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'C';
-- Things that shouldn't work:
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT ''not an integer'';';
ERROR: return type mismatch in function: declared to return integer, returns "unknown"
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'not even SQL';
ERROR: parser: parse error at or near "not"
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT 1, 2, 3;';
ERROR: function declared to return integer returns multiple columns in final SELECT
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT $2;';
ERROR: Parameter '$2' is out of range
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'a', 'b';
ERROR: CREATE FUNCTION: only one AS item needed for sql language
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE c
AS 'nosuchfile';
ERROR: stat failed on file 'nosuchfile': No such file or directory
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE c
AS '@abs_builddir@/regress@DLSUFFIX@', 'nosuchsymbol';
ERROR: Can't find function nosuchsymbol in file @abs_builddir@/regress@DLSUFFIX@
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE internal
AS 'nosuch';
ERROR: there is no built-in function named "nosuch"