Extend SQL function tests lightly
authorPeter Eisentraut
Sat, 5 Sep 2020 11:28:05 +0000 (13:28 +0200)
committerPeter Eisentraut
Sat, 5 Sep 2020 11:28:05 +0000 (13:28 +0200)
The basic tests that defined SQL functions didn't actually run the
functions to see if they worked.  Add that, and also fix a minor
mistake in a function that was revealed by this.  (This is not a
question of test coverage, since there are other places where SQL
functions are run, but it is a bit of a silly test design.)

Discussion: https://www.postgresql.org/message-id/flat/1c11f1eb-f00c-43b7-799d-2d44132c02d7@2ndquadrant.com

src/test/regress/expected/create_function_3.out
src/test/regress/sql/create_function_3.sql

index ba260df99607623360b6b4ea8a408fb9f89f1da9..ce508ae1dcc94a2a7067167e0bbd47098a003116 100644 (file)
@@ -17,7 +17,7 @@ SET search_path TO temp_func_test, public;
 CREATE FUNCTION functest_A_1(text, date) RETURNS bool LANGUAGE 'sql'
        AS 'SELECT $1 = ''abcd'' AND $2 > ''2001-01-01''';
 CREATE FUNCTION functest_A_2(text[]) RETURNS int LANGUAGE 'sql'
-       AS 'SELECT $1[0]::int';
+       AS 'SELECT $1[1]::int';
 CREATE FUNCTION functest_A_3() RETURNS bool LANGUAGE 'sql'
        AS 'SELECT false';
 SELECT proname, prorettype::regtype, proargtypes::regtype[] FROM pg_proc
@@ -31,6 +31,24 @@ SELECT proname, prorettype::regtype, proargtypes::regtype[] FROM pg_proc
  functest_a_3 | boolean    | {}
 (3 rows)
 
+SELECT functest_A_1('abcd', '2020-01-01');
+ functest_a_1 
+--------------
+ t
+(1 row)
+
+SELECT functest_A_2(ARRAY['1', '2', '3']);
+ functest_a_2 
+--------------
+            1
+(1 row)
+
+SELECT functest_A_3();
+ functest_a_3 
+--------------
+ f
+(1 row)
+
 --
 -- IMMUTABLE | STABLE | VOLATILE
 --
index 7a2df0ea8a1bc9cac28d3f70d861fd756514d041..bd108a918fbf0f214e0d88a3955270627cbe0c55 100644 (file)
@@ -23,7 +23,7 @@ SET search_path TO temp_func_test, public;
 CREATE FUNCTION functest_A_1(text, date) RETURNS bool LANGUAGE 'sql'
        AS 'SELECT $1 = ''abcd'' AND $2 > ''2001-01-01''';
 CREATE FUNCTION functest_A_2(text[]) RETURNS int LANGUAGE 'sql'
-       AS 'SELECT $1[0]::int';
+       AS 'SELECT $1[1]::int';
 CREATE FUNCTION functest_A_3() RETURNS bool LANGUAGE 'sql'
        AS 'SELECT false';
 SELECT proname, prorettype::regtype, proargtypes::regtype[] FROM pg_proc
@@ -31,6 +31,10 @@ SELECT proname, prorettype::regtype, proargtypes::regtype[] FROM pg_proc
                      'functest_A_2'::regproc,
                      'functest_A_3'::regproc) ORDER BY proname;
 
+SELECT functest_A_1('abcd', '2020-01-01');
+SELECT functest_A_2(ARRAY['1', '2', '3']);
+SELECT functest_A_3();
+
 --
 -- IMMUTABLE | STABLE | VOLATILE
 --