diff --git a/src/test/regress/expected/collate.out b/src/test/regress/expected/collate.out index 4ab9566..1b71dd1 100644 --- a/src/test/regress/expected/collate.out +++ b/src/test/regress/expected/collate.out @@ -604,6 +604,72 @@ SELECT collation for ((SELECT b FROM collate_test1 LIMIT 1)); "C" (1 row) +-- CREATE COLLATE tests +CREATE COLLATION c2 FROM "C"; +-- Ensure non-OWNER ROLEs are not able to ALTER/DROP COLLATION +CREATE ROLE role_collate1; +SET ROLE role_collate1; +DROP COLLATION c2; +ERROR: collation "c2" for encoding "UTF8" does not exist +ALTER COLLATION c2 OWNER TO role_collate1; +ERROR: collation "c2" for encoding "UTF8" does not exist +RESET ROLE; +-- Ensure ALTER COLLATION SET SCHEMA works as expected +CREATE SCHEMA collate_tests2; +ALTER COLLATION c2 SET SCHEMA collate_tests2; +DROP COLLATION collate_tests2.c2; +DROP SCHEMA collate_tests2; +-- Should work. Classic cases of CREATE/ALTER COLLATION +CREATE COLLATION c3 (LOCALE = 'C'); +ALTER COLLATION c3 OWNER TO role_collate1; +ALTER COLLATION c3 RENAME TO c33; +DROP COLLATION c33; +DROP ROLE role_collate1; +-- Should fail. Give redundant options +CREATE COLLATION c3a (LOCALE = 'C', LC_COLLATE = 'C', LC_CTYPE= 'C'); +ERROR: conflicting or redundant options +-- Should fail. LC_COLLATE must be specified +CREATE COLLATION c5 (LC_CTYPE= 'C'); +ERROR: parameter "lc_collate" must be specified +-- Should fail. Give value options without value +CREATE COLLATION c4a (LC_COLLATE = ''); +ERROR: parameter "lc_ctype" must be specified +CREATE COLLATION c5a (LC_CTYPE= ''); +ERROR: parameter "lc_collate" must be specified +-- Should fail. Give invalid option name +CREATE COLLATION c6 (ASDF = 'C'); +ERROR: collation attribute "asdf" not recognized +-- Ensure error is displayed when a collation already exists +CREATE COLLATION c7 (LOCALE = 'C'); +CREATE COLLATION c7a (LOCALE = 'C'); +ALTER COLLATION c7a RENAME TO c7; +ERROR: collation "c7" for encoding "UTF8" already exists in schema "collate_tests" +DROP COLLATION c7; +DROP COLLATION c7a; +-- Ensure error is displayed during ALTER SCHEMA when +-- the target SCHEMA already contains COLLATION of same name +CREATE COLLATION c8 (LOCALE = 'C'); +CREATE SCHEMA collate_tests3; +CREATE COLLATION collate_tests3.c8 (LOCALE = 'C'); +ALTER COLLATION c8 SET SCHEMA collate_tests3; +ERROR: collation "c8" for encoding "UTF8" already exists in schema "collate_tests3" +DROP SCHEMA collate_tests3 CASCADE; +NOTICE: drop cascades to collation c8 +DROP COLLATION c8; +-- Ensure ROLEs without USAGE access shouldn't be able to CREATE/ALTER COLLATION +CREATE SCHEMA collate_tests4; +CREATE COLLATION collate_tests4.c9 (LOCALE = 'C'); +CREATE ROLE role_collate2; +REVOKE USAGE ON SCHEMA collate_tests4 FROM role_collate2; +SET ROLE role_collate2; +ALTER COLLATION collate_tests4.c9 RENAME TO c9b; +ERROR: permission denied for schema collate_tests4 +CREATE COLLATION collate_tests4.c10 (LOCALE = 'C'); +ERROR: permission denied for schema collate_tests4 +RESET ROLE; +DROP ROLE role_collate2; +DROP SCHEMA collate_tests4 CASCADE; +NOTICE: drop cascades to collation c9 -- -- Clean up. Many of these table names will be re-used if the user is -- trying to run any platform-specific collation tests later, so we diff --git a/src/test/regress/sql/collate.sql b/src/test/regress/sql/collate.sql index 3c960e7..5baf2d2 100644 --- a/src/test/regress/sql/collate.sql +++ b/src/test/regress/sql/collate.sql @@ -225,6 +225,69 @@ SELECT collation for ('foo'::text); SELECT collation for ((SELECT a FROM collate_test1 LIMIT 1)); -- non-collatable type - error SELECT collation for ((SELECT b FROM collate_test1 LIMIT 1)); +-- CREATE COLLATE tests +CREATE COLLATION c2 FROM "C"; + +-- Ensure non-OWNER ROLEs are not able to ALTER/DROP COLLATION +CREATE ROLE role_collate1; +SET ROLE role_collate1; +DROP COLLATION c2; +ALTER COLLATION c2 OWNER TO role_collate1; +RESET ROLE; + +-- Ensure ALTER COLLATION SET SCHEMA works as expected +CREATE SCHEMA collate_tests2; +ALTER COLLATION c2 SET SCHEMA collate_tests2; +DROP COLLATION collate_tests2.c2; +DROP SCHEMA collate_tests2; + +-- Should work. Classic cases of CREATE/ALTER COLLATION +CREATE COLLATION c3 (LOCALE = 'C'); +ALTER COLLATION c3 OWNER TO role_collate1; +ALTER COLLATION c3 RENAME TO c33; +DROP COLLATION c33; +DROP ROLE role_collate1; + +-- Should fail. Give redundant options +CREATE COLLATION c3a (LOCALE = 'C', LC_COLLATE = 'C', LC_CTYPE= 'C'); + +-- Should fail. LC_COLLATE must be specified +CREATE COLLATION c5 (LC_CTYPE= 'C'); + +-- Should fail. Give value options without value +CREATE COLLATION c4a (LC_COLLATE = ''); +CREATE COLLATION c5a (LC_CTYPE= ''); + +-- Should fail. Give invalid option name +CREATE COLLATION c6 (ASDF = 'C'); + +-- Ensure error is displayed when a collation already exists +CREATE COLLATION c7 (LOCALE = 'C'); +CREATE COLLATION c7a (LOCALE = 'C'); +ALTER COLLATION c7a RENAME TO c7; +DROP COLLATION c7; +DROP COLLATION c7a; + +-- Ensure error is displayed during ALTER SCHEMA when +-- the target SCHEMA already contains COLLATION of same name +CREATE COLLATION c8 (LOCALE = 'C'); +CREATE SCHEMA collate_tests3; +CREATE COLLATION collate_tests3.c8 (LOCALE = 'C'); +ALTER COLLATION c8 SET SCHEMA collate_tests3; +DROP SCHEMA collate_tests3 CASCADE; +DROP COLLATION c8; + +-- Ensure ROLEs without USAGE access shouldn't be able to CREATE/ALTER COLLATION +CREATE SCHEMA collate_tests4; +CREATE COLLATION collate_tests4.c9 (LOCALE = 'C'); +CREATE ROLE role_collate2; +REVOKE USAGE ON SCHEMA collate_tests4 FROM role_collate2; +SET ROLE role_collate2; +ALTER COLLATION collate_tests4.c9 RENAME TO c9b; +CREATE COLLATION collate_tests4.c10 (LOCALE = 'C'); +RESET ROLE; +DROP ROLE role_collate2; +DROP SCHEMA collate_tests4 CASCADE; -- -- Clean up. Many of these table names will be re-used if the user is