1
1
--
2
2
-- CREATE FUNCTION
3
3
--
4
- -- sanity check of pg_proc catalog to the given parameters
4
+ -- Assorted tests using SQL-language functions
5
5
--
6
+ -- All objects made in this test are in temp_func_test schema
6
7
CREATE USER regress_unpriv_user;
7
8
CREATE SCHEMA temp_func_test;
8
9
GRANT ALL ON SCHEMA temp_func_test TO public;
9
10
SET search_path TO temp_func_test, public;
10
11
--
12
+ -- Make sanity checks on the pg_proc entries created by CREATE FUNCTION
13
+ --
14
+ --
11
15
-- ARGUMENT and RETURN TYPES
12
16
--
13
17
CREATE FUNCTION functest_A_1(text, date) RETURNS bool LANGUAGE 'sql'
@@ -127,7 +131,7 @@ SELECT proname, proleakproof FROM pg_proc
127
131
functest_e_2 | t
128
132
(2 rows)
129
133
130
- ALTER FUNCTION functest_E_2(int) NOT LEAKPROOF; -- remove leakproog attribute
134
+ ALTER FUNCTION functest_E_2(int) NOT LEAKPROOF; -- remove leakproof attribute
131
135
SELECT proname, proleakproof FROM pg_proc
132
136
WHERE oid in ('functest_E_1'::regproc,
133
137
'functest_E_2'::regproc) ORDER BY proname;
@@ -137,7 +141,7 @@ SELECT proname, proleakproof FROM pg_proc
137
141
functest_e_2 | f
138
142
(2 rows)
139
143
140
- -- it takes superuser privilege to turn on leakproof, but not for turn off
144
+ -- it takes superuser privilege to turn on leakproof, but not to turn off
141
145
ALTER FUNCTION functest_E_1(int) OWNER TO regress_unpriv_user;
142
146
ALTER FUNCTION functest_E_2(int) OWNER TO regress_unpriv_user;
143
147
SET SESSION AUTHORIZATION regress_unpriv_user;
@@ -146,7 +150,7 @@ ALTER FUNCTION functest_E_1(int) NOT LEAKPROOF;
146
150
ALTER FUNCTION functest_E_2(int) LEAKPROOF;
147
151
ERROR: only superuser can define a leakproof function
148
152
CREATE FUNCTION functest_E_3(int) RETURNS bool LANGUAGE 'sql'
149
- LEAKPROOF AS 'SELECT $1 < 200'; -- failed
153
+ LEAKPROOF AS 'SELECT $1 < 200'; -- fail
150
154
ERROR: only superuser can define a leakproof function
151
155
RESET SESSION AUTHORIZATION;
152
156
--
@@ -280,24 +284,66 @@ CREATE OR REPLACE PROCEDURE functest1(a int) LANGUAGE SQL AS 'SELECT $1';
280
284
ERROR: cannot change routine kind
281
285
DETAIL: "functest1" is a function.
282
286
DROP FUNCTION functest1(a int);
283
- -- Cleanups
287
+ -- Check behavior of VOID-returning SQL functions
288
+ CREATE FUNCTION voidtest1(a int) RETURNS VOID LANGUAGE SQL AS
289
+ $$ SELECT a + 1 $$;
290
+ SELECT voidtest1(42);
291
+ voidtest1
292
+ -----------
293
+
294
+ (1 row)
295
+
296
+ CREATE FUNCTION voidtest2(a int, b int) RETURNS VOID LANGUAGE SQL AS
297
+ $$ SELECT voidtest1(a + b) $$;
298
+ SELECT voidtest2(11,22);
299
+ voidtest2
300
+ -----------
301
+
302
+ (1 row)
303
+
304
+ -- currently, we can inline voidtest2 but not voidtest1
305
+ EXPLAIN (verbose, costs off) SELECT voidtest2(11,22);
306
+ QUERY PLAN
307
+ -------------------------
308
+ Result
309
+ Output: voidtest1(33)
310
+ (2 rows)
311
+
312
+ CREATE TEMP TABLE sometable(f1 int);
313
+ CREATE FUNCTION voidtest3(a int) RETURNS VOID LANGUAGE SQL AS
314
+ $$ INSERT INTO sometable VALUES(a + 1) $$;
315
+ SELECT voidtest3(17);
316
+ voidtest3
317
+ -----------
318
+
319
+ (1 row)
320
+
321
+ CREATE FUNCTION voidtest4(a int) RETURNS VOID LANGUAGE SQL AS
322
+ $$ INSERT INTO sometable VALUES(a - 1) RETURNING f1 $$;
323
+ SELECT voidtest4(39);
324
+ voidtest4
325
+ -----------
326
+
327
+ (1 row)
328
+
329
+ TABLE sometable;
330
+ f1
331
+ ----
332
+ 18
333
+ 38
334
+ (2 rows)
335
+
336
+ CREATE FUNCTION voidtest5(a int) RETURNS SETOF VOID LANGUAGE SQL AS
337
+ $$ SELECT generate_series(1, a) $$ STABLE;
338
+ SELECT * FROM voidtest5(3);
339
+ voidtest5
340
+ -----------
341
+ (0 rows)
342
+
343
+ -- Cleanup
344
+ \set VERBOSITY terse \\ -- suppress cascade details
284
345
DROP SCHEMA temp_func_test CASCADE;
285
- NOTICE: drop cascades to 16 other objects
286
- DETAIL: drop cascades to function functest_a_1(text,date)
287
- drop cascades to function functest_a_2(text[])
288
- drop cascades to function functest_a_3()
289
- drop cascades to function functest_b_2(integer)
290
- drop cascades to function functest_b_3(integer)
291
- drop cascades to function functest_b_4(integer)
292
- drop cascades to function functest_c_1(integer)
293
- drop cascades to function functest_c_2(integer)
294
- drop cascades to function functest_c_3(integer)
295
- drop cascades to function functest_e_1(integer)
296
- drop cascades to function functest_e_2(integer)
297
- drop cascades to function functest_f_1(integer)
298
- drop cascades to function functest_f_2(integer)
299
- drop cascades to function functest_f_3(integer)
300
- drop cascades to function functest_f_4(integer)
301
- drop cascades to function functest_b_2(bigint)
346
+ NOTICE: drop cascades to 21 other objects
347
+ \set VERBOSITY default
302
348
DROP USER regress_unpriv_user;
303
349
RESET search_path;
0 commit comments