aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/regress/expected/create_function_3.out25
-rw-r--r--src/test/regress/parallel_schedule3
-rw-r--r--src/test/regress/sql/create_function_3.sql23
3 files changed, 49 insertions, 2 deletions
diff --git a/src/test/regress/expected/create_function_3.out b/src/test/regress/expected/create_function_3.out
index 8dceb762e1b..eac3de57ccb 100644
--- a/src/test/regress/expected/create_function_3.out
+++ b/src/test/regress/expected/create_function_3.out
@@ -3,7 +3,9 @@
--
-- sanity check of pg_proc catalog to the given parameters
--
+CREATE USER regtest_unpriv_user;
CREATE SCHEMA temp_func_test;
+GRANT ALL ON SCHEMA temp_func_test TO public;
SET search_path TO temp_func_test, public;
--
-- ARGUMENT and RETURN TYPES
@@ -125,6 +127,28 @@ SELECT proname, proleakproof FROM pg_proc
functext_e_2 | t
(2 rows)
+ALTER FUNCTION functext_E_2(int) NOT LEAKPROOF; -- remove leakproog attribute
+SELECT proname, proleakproof FROM pg_proc
+ WHERE oid in ('functext_E_1'::regproc,
+ 'functext_E_2'::regproc) ORDER BY proname;
+ proname | proleakproof
+--------------+--------------
+ functext_e_1 | t
+ functext_e_2 | f
+(2 rows)
+
+-- it takes superuser privilege to turn on leakproof, but not for turn off
+ALTER FUNCTION functext_E_1(int) OWNER TO regtest_unpriv_user;
+ALTER FUNCTION functext_E_2(int) OWNER TO regtest_unpriv_user;
+SET SESSION AUTHORIZATION regtest_unpriv_user;
+SET search_path TO temp_func_test, public;
+ALTER FUNCTION functext_E_1(int) NOT LEAKPROOF;
+ALTER FUNCTION functext_E_2(int) LEAKPROOF;
+ERROR: only superuser can define a leakproof function
+CREATE FUNCTION functext_E_3(int) RETURNS bool LANGUAGE 'sql'
+ LEAKPROOF AS 'SELECT $1 < 200'; -- failed
+ERROR: only superuser can define a leakproof function
+RESET SESSION AUTHORIZATION;
-- list of built-in leakproof functions
SELECT proname, prorettype::regtype, proargtypes::regtype[]
FROM pg_proc JOIN pg_namespace ON pronamespace = pg_namespace.oid
@@ -420,4 +444,5 @@ drop cascades to function functext_f_1(integer)
drop cascades to function functext_f_2(integer)
drop cascades to function functext_f_3(integer)
drop cascades to function functext_f_4(integer)
+DROP USER regtest_unpriv_user;
RESET search_path;
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index 9749763ffd2..862f5b20077 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -40,7 +40,6 @@ test: create_function_1
test: create_type
test: create_table
test: create_function_2
-test: create_function_3
# ----------
# Load huge amounts of data
@@ -60,7 +59,7 @@ test: create_index create_view
# ----------
# Another group of parallel tests
# ----------
-test: create_aggregate create_cast constraints triggers inherit create_table_like typed_table vacuum drop_if_exists
+test: create_aggregate create_function_3 create_cast constraints triggers inherit create_table_like typed_table vacuum drop_if_exists
# ----------
# sanity_check does a vacuum, affecting the sort order of SELECT *
diff --git a/src/test/regress/sql/create_function_3.sql b/src/test/regress/sql/create_function_3.sql
index 56ed215a288..4693db63cdc 100644
--- a/src/test/regress/sql/create_function_3.sql
+++ b/src/test/regress/sql/create_function_3.sql
@@ -3,7 +3,10 @@
--
-- sanity check of pg_proc catalog to the given parameters
--
+CREATE USER regtest_unpriv_user;
+
CREATE SCHEMA temp_func_test;
+GRANT ALL ON SCHEMA temp_func_test TO public;
SET search_path TO temp_func_test, public;
@@ -85,6 +88,25 @@ SELECT proname, proleakproof FROM pg_proc
WHERE oid in ('functext_E_1'::regproc,
'functext_E_2'::regproc) ORDER BY proname;
+ALTER FUNCTION functext_E_2(int) NOT LEAKPROOF; -- remove leakproog attribute
+SELECT proname, proleakproof FROM pg_proc
+ WHERE oid in ('functext_E_1'::regproc,
+ 'functext_E_2'::regproc) ORDER BY proname;
+
+-- it takes superuser privilege to turn on leakproof, but not for turn off
+ALTER FUNCTION functext_E_1(int) OWNER TO regtest_unpriv_user;
+ALTER FUNCTION functext_E_2(int) OWNER TO regtest_unpriv_user;
+
+SET SESSION AUTHORIZATION regtest_unpriv_user;
+SET search_path TO temp_func_test, public;
+ALTER FUNCTION functext_E_1(int) NOT LEAKPROOF;
+ALTER FUNCTION functext_E_2(int) LEAKPROOF;
+
+CREATE FUNCTION functext_E_3(int) RETURNS bool LANGUAGE 'sql'
+ LEAKPROOF AS 'SELECT $1 < 200'; -- failed
+
+RESET SESSION AUTHORIZATION;
+
-- list of built-in leakproof functions
SELECT proname, prorettype::regtype, proargtypes::regtype[]
FROM pg_proc JOIN pg_namespace ON pronamespace = pg_namespace.oid
@@ -118,4 +140,5 @@ SELECT proname, proisstrict FROM pg_proc
-- Cleanups
DROP SCHEMA temp_func_test CASCADE;
+DROP USER regtest_unpriv_user;
RESET search_path;