2 * This test is for ICU collations.
4 /* skip test if not UTF8 server encoding or no ICU collations installed */
5 SELECT getdatabaseencoding() <> 'UTF8' OR
6 (SELECT count(*) FROM pg_collation WHERE collprovider = 'i') = 0
11 SET client_encoding TO UTF8;
12 CREATE SCHEMA collate_tests;
13 SET search_path = collate_tests;
14 CREATE TABLE collate_test1 (
16 b text COLLATE "en-x-icu" NOT NULL
19 Table "collate_tests.collate_test1"
20 Column | Type | Collation | Nullable | Default
21 --------+---------+-----------+----------+---------
23 b | text | en-x-icu | not null |
25 CREATE TABLE collate_test_fail (
27 b text COLLATE "ja_JP.eucjp-x-icu"
29 ERROR: collation "ja_JP.eucjp-x-icu" for encoding "UTF8" does not exist
30 LINE 3: b text COLLATE "ja_JP.eucjp-x-icu"
32 CREATE TABLE collate_test_fail (
34 b text COLLATE "foo-x-icu"
36 ERROR: collation "foo-x-icu" for encoding "UTF8" does not exist
37 LINE 3: b text COLLATE "foo-x-icu"
39 CREATE TABLE collate_test_fail (
40 a int COLLATE "en-x-icu",
43 ERROR: collations are not supported by type integer
44 LINE 2: a int COLLATE "en-x-icu",
46 CREATE TABLE collate_test_like (
50 Table "collate_tests.collate_test_like"
51 Column | Type | Collation | Nullable | Default
52 --------+---------+-----------+----------+---------
54 b | text | en-x-icu | not null |
56 CREATE TABLE collate_test2 (
58 b text COLLATE "sv-x-icu"
60 CREATE TABLE collate_test3 (
64 INSERT INTO collate_test1 VALUES (1, 'abc'), (2, 'äbc'), (3, 'bbc'), (4, 'ABC');
65 INSERT INTO collate_test2 SELECT * FROM collate_test1;
66 INSERT INTO collate_test3 SELECT * FROM collate_test1;
67 SELECT * FROM collate_test1 WHERE b >= 'bbc';
73 SELECT * FROM collate_test2 WHERE b >= 'bbc';
80 SELECT * FROM collate_test3 WHERE b >= 'bbc';
87 SELECT * FROM collate_test3 WHERE b >= 'BBC';
95 SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc';
102 SELECT * FROM collate_test1 WHERE b >= 'bbc' COLLATE "C";
109 SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "C";
116 SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "en-x-icu";
117 ERROR: collation mismatch between explicit collations "C" and "en-x-icu"
118 LINE 1: ...* FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "e...
120 CREATE DOMAIN testdomain_sv AS text COLLATE "sv-x-icu";
121 CREATE DOMAIN testdomain_i AS int COLLATE "sv-x-icu"; -- fails
122 ERROR: collations are not supported by type integer
123 CREATE TABLE collate_test4 (
127 INSERT INTO collate_test4 SELECT * FROM collate_test1;
128 SELECT a, b FROM collate_test4 ORDER BY b;
137 CREATE TABLE collate_test5 (
139 b testdomain_sv COLLATE "en-x-icu"
141 INSERT INTO collate_test5 SELECT * FROM collate_test1;
142 SELECT a, b FROM collate_test5 ORDER BY b;
151 SELECT a, b FROM collate_test1 ORDER BY b;
160 SELECT a, b FROM collate_test2 ORDER BY b;
169 SELECT a, b FROM collate_test3 ORDER BY b;
178 SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C";
188 SELECT * FROM collate_test1 ORDER BY b;
197 SELECT * FROM collate_test2 ORDER BY b;
206 SELECT * FROM collate_test3 ORDER BY b;
215 -- constant expression folding
216 SELECT 'bbc' COLLATE "en-x-icu" > 'äbc' COLLATE "en-x-icu" AS "true";
222 SELECT 'bbc' COLLATE "sv-x-icu" > 'äbc' COLLATE "sv-x-icu" AS "false";
229 CREATE TABLE collate_test10 (
231 x text COLLATE "en-x-icu",
232 y text COLLATE "tr-x-icu"
234 INSERT INTO collate_test10 VALUES (1, 'hij', 'hij'), (2, 'HIJ', 'HIJ');
235 SELECT a, lower(x), lower(y), upper(x), upper(y), initcap(x), initcap(y) FROM collate_test10;
236 a | lower | lower | upper | upper | initcap | initcap
237 ---+-------+-------+-------+-------+---------+---------
238 1 | hij | hij | HIJ | HİJ | Hij | Hij
239 2 | hij | hıj | HIJ | HIJ | Hij | Hıj
242 SELECT a, lower(x COLLATE "C"), lower(y COLLATE "C") FROM collate_test10;
249 SELECT a, x, y FROM collate_test10 ORDER BY lower(y), a;
257 SELECT * FROM collate_test1 WHERE b LIKE 'abc';
263 SELECT * FROM collate_test1 WHERE b LIKE 'abc%';
269 SELECT * FROM collate_test1 WHERE b LIKE '%bc%';
277 SELECT * FROM collate_test1 WHERE b ILIKE 'abc';
284 SELECT * FROM collate_test1 WHERE b ILIKE 'abc%';
291 SELECT * FROM collate_test1 WHERE b ILIKE '%bc%';
300 SELECT 'Türkiye' COLLATE "en-x-icu" ILIKE '%KI%' AS "true";
306 SELECT 'Türkiye' COLLATE "tr-x-icu" ILIKE '%KI%' AS "false";
312 SELECT 'bıt' ILIKE 'BIT' COLLATE "en-x-icu" AS "false";
318 SELECT 'bıt' ILIKE 'BIT' COLLATE "tr-x-icu" AS "true";
324 -- The following actually exercises the selectivity estimation for ILIKE.
325 SELECT relname FROM pg_class WHERE relname ILIKE 'abc%';
330 -- regular expressions
331 SELECT * FROM collate_test1 WHERE b ~ '^abc$';
337 SELECT * FROM collate_test1 WHERE b ~ '^abc';
343 SELECT * FROM collate_test1 WHERE b ~ 'bc';
351 SELECT * FROM collate_test1 WHERE b ~* '^abc$';
358 SELECT * FROM collate_test1 WHERE b ~* '^abc';
365 SELECT * FROM collate_test1 WHERE b ~* 'bc';
374 CREATE TABLE collate_test6 (
376 b text COLLATE "en-x-icu"
378 INSERT INTO collate_test6 VALUES (1, 'abc'), (2, 'ABC'), (3, '123'), (4, 'ab1'),
379 (5, 'a1!'), (6, 'a c'), (7, '!.;'), (8, ' '),
380 (9, 'äbç'), (10, 'ÄBÇ');
382 b ~ '^[[:alpha:]]+$' AS is_alpha,
383 b ~ '^[[:upper:]]+$' AS is_upper,
384 b ~ '^[[:lower:]]+$' AS is_lower,
385 b ~ '^[[:digit:]]+$' AS is_digit,
386 b ~ '^[[:alnum:]]+$' AS is_alnum,
387 b ~ '^[[:graph:]]+$' AS is_graph,
388 b ~ '^[[:print:]]+$' AS is_print,
389 b ~ '^[[:punct:]]+$' AS is_punct,
390 b ~ '^[[:space:]]+$' AS is_space
392 b | is_alpha | is_upper | is_lower | is_digit | is_alnum | is_graph | is_print | is_punct | is_space
393 -----+----------+----------+----------+----------+----------+----------+----------+----------+----------
394 abc | t | f | t | f | t | t | t | f | f
395 ABC | t | t | f | f | t | t | t | f | f
396 123 | f | f | f | t | t | t | t | f | f
397 ab1 | f | f | f | f | t | t | t | f | f
398 a1! | f | f | f | f | f | t | t | f | f
399 a c | f | f | f | f | f | f | t | f | f
400 !.; | f | f | f | f | f | t | t | t | f
401 | f | f | f | f | f | f | t | f | t
402 äbç | t | f | t | f | t | t | t | f | f
403 ÄBÇ | t | t | f | f | t | t | t | f | f
406 SELECT 'Türkiye' COLLATE "en-x-icu" ~* 'KI' AS "true";
412 SELECT 'Türkiye' COLLATE "tr-x-icu" ~* 'KI' AS "true"; -- true with ICU
418 SELECT 'bıt' ~* 'BIT' COLLATE "en-x-icu" AS "false";
424 SELECT 'bıt' ~* 'BIT' COLLATE "tr-x-icu" AS "false"; -- false with ICU
430 -- The following actually exercises the selectivity estimation for ~*.
431 SELECT relname FROM pg_class WHERE relname ~* '^abc';
436 /* not run by default because it requires tr_TR system locale
439 SET lc_time TO 'tr_TR';
440 SELECT to_char(date '2010-04-01', 'DD TMMON YYYY');
441 SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr-x-icu");
444 CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc';
445 CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C";
446 CREATE VIEW collview3 AS SELECT a, lower((x || x) COLLATE "C") FROM collate_test10;
447 SELECT table_name, view_definition FROM information_schema.views
448 WHERE table_name LIKE 'collview%' ORDER BY 1;
449 table_name | view_definition
450 ------------+--------------------------------------------------------------------------
451 collview1 | SELECT collate_test1.a, +
453 | FROM collate_test1 +
454 | WHERE ((collate_test1.b COLLATE "C") >= 'bbc'::text);
455 collview2 | SELECT collate_test1.a, +
457 | FROM collate_test1 +
458 | ORDER BY (collate_test1.b COLLATE "C");
459 collview3 | SELECT collate_test10.a, +
460 | lower(((collate_test10.x || collate_test10.x) COLLATE "C")) AS lower+
461 | FROM collate_test10;
464 -- collation propagation in various expression types
465 SELECT a, coalesce(b, 'foo') FROM collate_test1 ORDER BY 2;
474 SELECT a, coalesce(b, 'foo') FROM collate_test2 ORDER BY 2;
483 SELECT a, coalesce(b, 'foo') FROM collate_test3 ORDER BY 2;
492 SELECT a, lower(coalesce(x, 'foo')), lower(coalesce(y, 'foo')) FROM collate_test10;
499 SELECT a, b, greatest(b, 'CCC') FROM collate_test1 ORDER BY 3;
508 SELECT a, b, greatest(b, 'CCC') FROM collate_test2 ORDER BY 3;
517 SELECT a, b, greatest(b, 'CCC') FROM collate_test3 ORDER BY 3;
526 SELECT a, x, y, lower(greatest(x, 'foo')), lower(greatest(y, 'foo')) FROM collate_test10;
527 a | x | y | lower | lower
528 ---+-----+-----+-------+-------
529 1 | hij | hij | hij | hij
530 2 | HIJ | HIJ | hij | hıj
533 SELECT a, nullif(b, 'abc') FROM collate_test1 ORDER BY 2;
542 SELECT a, nullif(b, 'abc') FROM collate_test2 ORDER BY 2;
551 SELECT a, nullif(b, 'abc') FROM collate_test3 ORDER BY 2;
560 SELECT a, lower(nullif(x, 'foo')), lower(nullif(y, 'foo')) FROM collate_test10;
567 SELECT a, CASE b WHEN 'abc' THEN 'abcd' ELSE b END FROM collate_test1 ORDER BY 2;
576 SELECT a, CASE b WHEN 'abc' THEN 'abcd' ELSE b END FROM collate_test2 ORDER BY 2;
585 SELECT a, CASE b WHEN 'abc' THEN 'abcd' ELSE b END FROM collate_test3 ORDER BY 2;
594 CREATE DOMAIN testdomain AS text;
595 SELECT a, b::testdomain FROM collate_test1 ORDER BY 2;
604 SELECT a, b::testdomain FROM collate_test2 ORDER BY 2;
613 SELECT a, b::testdomain FROM collate_test3 ORDER BY 2;
622 SELECT a, b::testdomain_sv FROM collate_test3 ORDER BY 2;
631 SELECT a, lower(x::testdomain), lower(y::testdomain) FROM collate_test10;
638 SELECT min(b), max(b) FROM collate_test1;
644 SELECT min(b), max(b) FROM collate_test2;
650 SELECT min(b), max(b) FROM collate_test3;
656 SELECT array_agg(b ORDER BY b) FROM collate_test1;
662 SELECT array_agg(b ORDER BY b) FROM collate_test2;
668 SELECT array_agg(b ORDER BY b) FROM collate_test3;
674 SELECT a, b FROM collate_test1 UNION ALL SELECT a, b FROM collate_test1 ORDER BY 2;
687 SELECT a, b FROM collate_test2 UNION SELECT a, b FROM collate_test2 ORDER BY 2;
696 SELECT a, b FROM collate_test3 WHERE a < 4 INTERSECT SELECT a, b FROM collate_test3 WHERE a > 1 ORDER BY 2;
703 SELECT a, b FROM collate_test3 EXCEPT SELECT a, b FROM collate_test3 WHERE a < 2 ORDER BY 2;
711 SELECT a, b FROM collate_test1 UNION ALL SELECT a, b FROM collate_test3 ORDER BY 2; -- fail
712 ERROR: could not determine which collation to use for string comparison
713 HINT: Use the COLLATE clause to set the collation explicitly.
714 SELECT a, b FROM collate_test1 UNION ALL SELECT a, b FROM collate_test3; -- ok
727 SELECT a, b FROM collate_test1 UNION SELECT a, b FROM collate_test3 ORDER BY 2; -- fail
728 ERROR: collation mismatch between implicit collations "en-x-icu" and "C"
729 LINE 1: SELECT a, b FROM collate_test1 UNION SELECT a, b FROM collat...
731 HINT: You can choose the collation by applying the COLLATE clause to one or both expressions.
732 SELECT a, b COLLATE "C" FROM collate_test1 UNION SELECT a, b FROM collate_test3 ORDER BY 2; -- ok
741 SELECT a, b FROM collate_test1 INTERSECT SELECT a, b FROM collate_test3 ORDER BY 2; -- fail
742 ERROR: collation mismatch between implicit collations "en-x-icu" and "C"
743 LINE 1: ...ELECT a, b FROM collate_test1 INTERSECT SELECT a, b FROM col...
745 HINT: You can choose the collation by applying the COLLATE clause to one or both expressions.
746 SELECT a, b FROM collate_test1 EXCEPT SELECT a, b FROM collate_test3 ORDER BY 2; -- fail
747 ERROR: collation mismatch between implicit collations "en-x-icu" and "C"
748 LINE 1: SELECT a, b FROM collate_test1 EXCEPT SELECT a, b FROM colla...
750 HINT: You can choose the collation by applying the COLLATE clause to one or both expressions.
751 CREATE TABLE test_u AS SELECT a, b FROM collate_test1 UNION ALL SELECT a, b FROM collate_test3; -- fail
752 ERROR: no collation was derived for column "b" with collatable type text
753 HINT: Use the COLLATE clause to set the collation explicitly.
754 -- ideally this would be a parse-time error, but for now it must be run-time:
755 select x < y from collate_test10; -- fail
756 ERROR: could not determine which collation to use for string comparison
757 HINT: Use the COLLATE clause to set the collation explicitly.
758 select x || y from collate_test10; -- ok, because || is not collation aware
765 select x, y from collate_test10 order by x || y; -- not so ok
766 ERROR: collation mismatch between implicit collations "en-x-icu" and "tr-x-icu"
767 LINE 1: select x, y from collate_test10 order by x || y;
769 HINT: You can choose the collation by applying the COLLATE clause to one or both expressions.
770 -- collation mismatch between recursive and non-recursive term
771 WITH RECURSIVE foo(x) AS
772 (SELECT x FROM (VALUES('a' COLLATE "en-x-icu"),('b')) t(x)
774 SELECT (x || 'c') COLLATE "de-x-icu" FROM foo WHERE length(x) < 10)
776 ERROR: recursive query "foo" column 1 has collation "en-x-icu" in non-recursive term but collation "de-x-icu" overall
777 LINE 2: (SELECT x FROM (VALUES('a' COLLATE "en-x-icu"),('b')) t(x...
779 HINT: Use the COLLATE clause to set the collation of the non-recursive term.
781 SELECT CAST('42' AS text COLLATE "C");
782 ERROR: syntax error at or near "COLLATE"
783 LINE 1: SELECT CAST('42' AS text COLLATE "C");
785 SELECT a, CAST(b AS varchar) FROM collate_test1 ORDER BY 2;
794 SELECT a, CAST(b AS varchar) FROM collate_test2 ORDER BY 2;
803 SELECT a, CAST(b AS varchar) FROM collate_test3 ORDER BY 2;
812 -- propagation of collation in SQL functions (inlined and non-inlined cases)
813 -- and plpgsql functions too
814 CREATE FUNCTION mylt (text, text) RETURNS boolean LANGUAGE sql
815 AS $$ select $1 < $2 $$;
816 CREATE FUNCTION mylt_noninline (text, text) RETURNS boolean LANGUAGE sql
817 AS $$ select $1 < $2 limit 1 $$;
818 CREATE FUNCTION mylt_plpgsql (text, text) RETURNS boolean LANGUAGE plpgsql
819 AS $$ begin return $1 < $2; end $$;
820 SELECT a.b AS a, b.b AS b, a.b < b.b AS lt,
821 mylt(a.b, b.b), mylt_noninline(a.b, b.b), mylt_plpgsql(a.b, b.b)
822 FROM collate_test1 a, collate_test1 b
824 a | b | lt | mylt | mylt_noninline | mylt_plpgsql
825 -----+-----+----+------+----------------+--------------
826 abc | abc | f | f | f | f
827 abc | ABC | t | t | t | t
828 abc | äbc | t | t | t | t
829 abc | bbc | t | t | t | t
830 ABC | abc | f | f | f | f
831 ABC | ABC | f | f | f | f
832 ABC | äbc | t | t | t | t
833 ABC | bbc | t | t | t | t
834 äbc | abc | f | f | f | f
835 äbc | ABC | f | f | f | f
836 äbc | äbc | f | f | f | f
837 äbc | bbc | t | t | t | t
838 bbc | abc | f | f | f | f
839 bbc | ABC | f | f | f | f
840 bbc | äbc | f | f | f | f
841 bbc | bbc | f | f | f | f
844 SELECT a.b AS a, b.b AS b, a.b < b.b COLLATE "C" AS lt,
845 mylt(a.b, b.b COLLATE "C"), mylt_noninline(a.b, b.b COLLATE "C"),
846 mylt_plpgsql(a.b, b.b COLLATE "C")
847 FROM collate_test1 a, collate_test1 b
849 a | b | lt | mylt | mylt_noninline | mylt_plpgsql
850 -----+-----+----+------+----------------+--------------
851 abc | abc | f | f | f | f
852 abc | ABC | f | f | f | f
853 abc | äbc | t | t | t | t
854 abc | bbc | t | t | t | t
855 ABC | abc | t | t | t | t
856 ABC | ABC | f | f | f | f
857 ABC | äbc | t | t | t | t
858 ABC | bbc | t | t | t | t
859 äbc | abc | f | f | f | f
860 äbc | ABC | f | f | f | f
861 äbc | äbc | f | f | f | f
862 äbc | bbc | f | f | f | f
863 bbc | abc | f | f | f | f
864 bbc | ABC | f | f | f | f
865 bbc | äbc | t | t | t | t
866 bbc | bbc | f | f | f | f
869 -- collation override in plpgsql
870 CREATE FUNCTION mylt2 (x text, y text) RETURNS boolean LANGUAGE plpgsql AS $$
878 SELECT mylt2('a', 'B' collate "en-x-icu") as t, mylt2('a', 'B' collate "C") as f;
884 CREATE OR REPLACE FUNCTION
885 mylt2 (x text, y text) RETURNS boolean LANGUAGE plpgsql AS $$
887 xx text COLLATE "POSIX" := x;
893 SELECT mylt2('a', 'B') as f;
899 SELECT mylt2('a', 'B' collate "C") as fail; -- conflicting collations
900 ERROR: could not determine which collation to use for string comparison
901 HINT: Use the COLLATE clause to set the collation explicitly.
902 CONTEXT: PL/pgSQL function mylt2(text,text) line 6 at RETURN
903 SELECT mylt2('a', 'B' collate "POSIX") as f;
910 SELECT * FROM unnest((SELECT array_agg(b ORDER BY b) FROM collate_test1)) ORDER BY 1;
919 SELECT * FROM unnest((SELECT array_agg(b ORDER BY b) FROM collate_test2)) ORDER BY 1;
928 SELECT * FROM unnest((SELECT array_agg(b ORDER BY b) FROM collate_test3)) ORDER BY 1;
937 CREATE FUNCTION dup (anyelement) RETURNS anyelement
938 AS 'select $1' LANGUAGE sql;
939 SELECT a, dup(b) FROM collate_test1 ORDER BY 2;
948 SELECT a, dup(b) FROM collate_test2 ORDER BY 2;
957 SELECT a, dup(b) FROM collate_test3 ORDER BY 2;
967 CREATE INDEX collate_test1_idx1 ON collate_test1 (b);
968 CREATE INDEX collate_test1_idx2 ON collate_test1 (b COLLATE "C");
969 CREATE INDEX collate_test1_idx3 ON collate_test1 ((b COLLATE "C")); -- this is different grammatically
970 CREATE INDEX collate_test1_idx4 ON collate_test1 (((b||'foo') COLLATE "POSIX"));
971 CREATE INDEX collate_test1_idx5 ON collate_test1 (a COLLATE "C"); -- fail
972 ERROR: collations are not supported by type integer
973 CREATE INDEX collate_test1_idx6 ON collate_test1 ((a COLLATE "C")); -- fail
974 ERROR: collations are not supported by type integer
975 LINE 1: ...ATE INDEX collate_test1_idx6 ON collate_test1 ((a COLLATE "C...
977 SELECT relname, pg_get_indexdef(oid) FROM pg_class WHERE relname LIKE 'collate_test%_idx%' ORDER BY 1;
978 relname | pg_get_indexdef
979 --------------------+-------------------------------------------------------------------------------------------------------------------
980 collate_test1_idx1 | CREATE INDEX collate_test1_idx1 ON collate_tests.collate_test1 USING btree (b)
981 collate_test1_idx2 | CREATE INDEX collate_test1_idx2 ON collate_tests.collate_test1 USING btree (b COLLATE "C")
982 collate_test1_idx3 | CREATE INDEX collate_test1_idx3 ON collate_tests.collate_test1 USING btree (b COLLATE "C")
983 collate_test1_idx4 | CREATE INDEX collate_test1_idx4 ON collate_tests.collate_test1 USING btree (((b || 'foo'::text)) COLLATE "POSIX")
986 set enable_seqscan = off;
988 select * from collate_test1 where b ilike 'abc';
990 -------------------------------
991 Seq Scan on collate_test1
992 Filter: (b ~~* 'abc'::text)
995 select * from collate_test1 where b ilike 'abc';
1003 select * from collate_test1 where b ilike 'ABC';
1005 -------------------------------
1006 Seq Scan on collate_test1
1007 Filter: (b ~~* 'ABC'::text)
1010 select * from collate_test1 where b ilike 'ABC';
1017 reset enable_seqscan;
1018 -- schema manipulation commands
1019 CREATE ROLE regress_test_role;
1020 CREATE SCHEMA test_schema;
1021 -- We need to do this this way to cope with varying names for encodings:
1024 EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' ||
1025 quote_literal(current_setting('lc_collate')) || ');';
1028 CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
1029 ERROR: collation "test0" already exists
1032 EXECUTE 'CREATE COLLATION test1 (provider = icu, lc_collate = ' ||
1033 quote_literal(current_setting('lc_collate')) ||
1035 quote_literal(current_setting('lc_ctype')) || ');';
1038 CREATE COLLATION test3 (provider = icu, lc_collate = 'en_US.utf8'); -- fail, need lc_ctype
1039 ERROR: parameter "lc_ctype" must be specified
1040 CREATE COLLATION testx (provider = icu, locale = 'nonsense'); /* never fails with ICU */ DROP COLLATION testx;
1041 CREATE COLLATION test4 FROM nonsense;
1042 ERROR: collation "nonsense" for encoding "UTF8" does not exist
1043 CREATE COLLATION test5 FROM test0;
1044 SELECT collname FROM pg_collation WHERE collname LIKE 'test%' ORDER BY 1;
1052 ALTER COLLATION test1 RENAME TO test11;
1053 ALTER COLLATION test0 RENAME TO test11; -- fail
1054 ERROR: collation "test11" already exists in schema "collate_tests"
1055 ALTER COLLATION test1 RENAME TO test22; -- fail
1056 ERROR: collation "test1" for encoding "UTF8" does not exist
1057 ALTER COLLATION test11 OWNER TO regress_test_role;
1058 ALTER COLLATION test11 OWNER TO nonsense;
1059 ERROR: role "nonsense" does not exist
1060 ALTER COLLATION test11 SET SCHEMA test_schema;
1061 COMMENT ON COLLATION test0 IS 'US English';
1062 SELECT collname, nspname, obj_description(pg_collation.oid, 'pg_collation')
1063 FROM pg_collation JOIN pg_namespace ON (collnamespace = pg_namespace.oid)
1064 WHERE collname LIKE 'test%'
1066 collname | nspname | obj_description
1067 ----------+---------------+-----------------
1068 test0 | collate_tests | US English
1069 test11 | test_schema |
1070 test5 | collate_tests |
1073 DROP COLLATION test0, test_schema.test11, test5;
1074 DROP COLLATION test0; -- fail
1075 ERROR: collation "test0" for encoding "UTF8" does not exist
1076 DROP COLLATION IF EXISTS test0;
1077 NOTICE: collation "test0" does not exist, skipping
1078 SELECT collname FROM pg_collation WHERE collname LIKE 'test%';
1083 DROP SCHEMA test_schema;
1084 DROP ROLE regress_test_role;
1086 ALTER COLLATION "en-x-icu" REFRESH VERSION;
1087 NOTICE: version has not changed
1089 CREATE COLLATION test0 FROM "C";
1090 CREATE TABLE collate_dep_test1 (a int, b text COLLATE test0);
1091 CREATE DOMAIN collate_dep_dom1 AS text COLLATE test0;
1092 CREATE TYPE collate_dep_test2 AS (x int, y text COLLATE test0);
1093 CREATE VIEW collate_dep_test3 AS SELECT text 'foo' COLLATE test0 AS foo;
1094 CREATE TABLE collate_dep_test4t (a int, b text);
1095 CREATE INDEX collate_dep_test4i ON collate_dep_test4t (b COLLATE test0);
1096 DROP COLLATION test0 RESTRICT; -- fail
1097 ERROR: cannot drop collation test0 because other objects depend on it
1098 DETAIL: column b of table collate_dep_test1 depends on collation test0
1099 type collate_dep_dom1 depends on collation test0
1100 column y of composite type collate_dep_test2 depends on collation test0
1101 view collate_dep_test3 depends on collation test0
1102 index collate_dep_test4i depends on collation test0
1103 HINT: Use DROP ... CASCADE to drop the dependent objects too.
1104 DROP COLLATION test0 CASCADE;
1105 NOTICE: drop cascades to 5 other objects
1106 DETAIL: drop cascades to column b of table collate_dep_test1
1107 drop cascades to type collate_dep_dom1
1108 drop cascades to column y of composite type collate_dep_test2
1109 drop cascades to view collate_dep_test3
1110 drop cascades to index collate_dep_test4i
1111 \d collate_dep_test1
1112 Table "collate_tests.collate_dep_test1"
1113 Column | Type | Collation | Nullable | Default
1114 --------+---------+-----------+----------+---------
1117 \d collate_dep_test2
1118 Composite type "collate_tests.collate_dep_test2"
1119 Column | Type | Collation | Nullable | Default
1120 --------+---------+-----------+----------+---------
1123 DROP TABLE collate_dep_test1, collate_dep_test4t;
1124 DROP TYPE collate_dep_test2;
1125 -- test range types and collations
1126 create type textrange_c as range(subtype=text, collation="C");
1127 create type textrange_en_us as range(subtype=text, collation="en-x-icu");
1128 select textrange_c('A','Z') @> 'b'::text;
1134 select textrange_en_us('A','Z') @> 'b'::text;
1140 drop type textrange_c;
1141 drop type textrange_en_us;
1142 -- test ICU collation customization
1143 -- test the attributes handled by icu_set_collation_attributes()
1144 CREATE COLLATION testcoll_ignore_accents (provider = icu, locale = '@colStrength=primary;colCaseLevel=yes');
1145 SELECT 'aaá' > 'AAA' COLLATE "und-x-icu", 'aaá' < 'AAA' COLLATE testcoll_ignore_accents;
1147 ----------+----------
1151 CREATE COLLATION testcoll_backwards (provider = icu, locale = '@colBackwards=yes');
1152 SELECT 'coté' < 'côte' COLLATE "und-x-icu", 'coté' > 'côte' COLLATE testcoll_backwards;
1154 ----------+----------
1158 CREATE COLLATION testcoll_lower_first (provider = icu, locale = '@colCaseFirst=lower');
1159 CREATE COLLATION testcoll_upper_first (provider = icu, locale = '@colCaseFirst=upper');
1160 SELECT 'aaa' < 'AAA' COLLATE testcoll_lower_first, 'aaa' > 'AAA' COLLATE testcoll_upper_first;
1162 ----------+----------
1166 CREATE COLLATION testcoll_shifted (provider = icu, locale = '@colAlternate=shifted');
1167 SELECT 'de-luge' < 'deanza' COLLATE "und-x-icu", 'de-luge' > 'deanza' COLLATE testcoll_shifted;
1169 ----------+----------
1173 CREATE COLLATION testcoll_numeric (provider = icu, locale = '@colNumeric=yes');
1174 SELECT 'A-21' > 'A-123' COLLATE "und-x-icu", 'A-21' < 'A-123' COLLATE testcoll_numeric;
1176 ----------+----------
1180 CREATE COLLATION testcoll_error1 (provider = icu, locale = '@colNumeric=lower');
1181 ERROR: could not open collator for locale "@colNumeric=lower": U_ILLEGAL_ARGUMENT_ERROR
1182 -- test that attributes not handled by icu_set_collation_attributes()
1183 -- (handled by ucol_open() directly) also work
1184 CREATE COLLATION testcoll_de_phonebook (provider = icu, locale = 'de@collation=phonebook');
1185 SELECT 'Goldmann' < 'Götz' COLLATE "de-x-icu", 'Goldmann' > 'Götz' COLLATE testcoll_de_phonebook;
1187 ----------+----------
1191 -- nondeterministic collations
1192 CREATE COLLATION ctest_det (provider = icu, locale = '', deterministic = true);
1193 CREATE COLLATION ctest_nondet (provider = icu, locale = '', deterministic = false);
1194 CREATE TABLE test6 (a int, b text);
1195 -- same string in different normal forms
1196 INSERT INTO test6 VALUES (1, U&'\00E4bc');
1197 INSERT INTO test6 VALUES (2, U&'\0061\0308bc');
1198 SELECT * FROM test6;
1205 SELECT * FROM test6 WHERE b = 'äbc' COLLATE ctest_det;
1211 SELECT * FROM test6 WHERE b = 'äbc' COLLATE ctest_nondet;
1219 CREATE TABLE test6a (a int, b text[]);
1220 INSERT INTO test6a VALUES (1, ARRAY[U&'\00E4bc']);
1221 INSERT INTO test6a VALUES (2, ARRAY[U&'\0061\0308bc']);
1222 SELECT * FROM test6a;
1229 SELECT * FROM test6a WHERE b = ARRAY['äbc'] COLLATE ctest_det;
1235 SELECT * FROM test6a WHERE b = ARRAY['äbc'] COLLATE ctest_nondet;
1242 CREATE COLLATION case_sensitive (provider = icu, locale = '');
1243 CREATE COLLATION case_insensitive (provider = icu, locale = '@colStrength=secondary', deterministic = false);
1244 SELECT 'abc' <= 'ABC' COLLATE case_sensitive, 'abc' >= 'ABC' COLLATE case_sensitive;
1246 ----------+----------
1250 SELECT 'abc' <= 'ABC' COLLATE case_insensitive, 'abc' >= 'ABC' COLLATE case_insensitive;
1252 ----------+----------
1256 CREATE TABLE test1cs (x text COLLATE case_sensitive);
1257 CREATE TABLE test2cs (x text COLLATE case_sensitive);
1258 CREATE TABLE test3cs (x text COLLATE case_sensitive);
1259 INSERT INTO test1cs VALUES ('abc'), ('def'), ('ghi');
1260 INSERT INTO test2cs VALUES ('ABC'), ('ghi');
1261 INSERT INTO test3cs VALUES ('abc'), ('ABC'), ('def'), ('ghi');
1262 SELECT x FROM test3cs WHERE x = 'abc';
1268 SELECT x FROM test3cs WHERE x <> 'abc';
1276 SELECT x FROM test3cs WHERE x LIKE 'a%';
1282 SELECT x FROM test3cs WHERE x ILIKE 'a%';
1289 SELECT x FROM test3cs WHERE x SIMILAR TO 'a%';
1295 SELECT x FROM test3cs WHERE x ~ 'a';
1301 SELECT x FROM test1cs UNION SELECT x FROM test2cs ORDER BY x;
1310 SELECT x FROM test2cs UNION SELECT x FROM test1cs ORDER BY x;
1319 SELECT x FROM test1cs INTERSECT SELECT x FROM test2cs;
1325 SELECT x FROM test2cs INTERSECT SELECT x FROM test1cs;
1331 SELECT x FROM test1cs EXCEPT SELECT x FROM test2cs;
1338 SELECT x FROM test2cs EXCEPT SELECT x FROM test1cs;
1344 SELECT DISTINCT x FROM test3cs ORDER BY x;
1353 SELECT count(DISTINCT x) FROM test3cs;
1359 SELECT x, count(*) FROM test3cs GROUP BY x ORDER BY x;
1368 SELECT x, row_number() OVER (ORDER BY x), rank() OVER (ORDER BY x) FROM test3cs ORDER BY x;
1369 x | row_number | rank
1370 -----+------------+------
1377 CREATE UNIQUE INDEX ON test1cs (x); -- ok
1378 INSERT INTO test1cs VALUES ('ABC'); -- ok
1379 CREATE UNIQUE INDEX ON test3cs (x); -- ok
1380 SELECT string_to_array('ABC,DEF,GHI' COLLATE case_sensitive, ',', 'abc');
1386 SELECT string_to_array('ABCDEFGHI' COLLATE case_sensitive, NULL, 'b');
1388 ---------------------
1392 CREATE TABLE test1ci (x text COLLATE case_insensitive);
1393 CREATE TABLE test2ci (x text COLLATE case_insensitive);
1394 CREATE TABLE test3ci (x text COLLATE case_insensitive);
1395 CREATE INDEX ON test3ci (x text_pattern_ops); -- error
1396 ERROR: nondeterministic collations are not supported for operator class "text_pattern_ops"
1397 INSERT INTO test1ci VALUES ('abc'), ('def'), ('ghi');
1398 INSERT INTO test2ci VALUES ('ABC'), ('ghi');
1399 INSERT INTO test3ci VALUES ('abc'), ('ABC'), ('def'), ('ghi');
1400 SELECT x FROM test3ci WHERE x = 'abc';
1407 SELECT x FROM test3ci WHERE x <> 'abc';
1414 SELECT x FROM test3ci WHERE x LIKE 'a%';
1415 ERROR: nondeterministic collations are not supported for LIKE
1416 SELECT x FROM test3ci WHERE x ILIKE 'a%';
1417 ERROR: nondeterministic collations are not supported for ILIKE
1418 SELECT x FROM test3ci WHERE x SIMILAR TO 'a%';
1419 ERROR: nondeterministic collations are not supported for regular expressions
1420 SELECT x FROM test3ci WHERE x ~ 'a';
1421 ERROR: nondeterministic collations are not supported for regular expressions
1422 SELECT x FROM test1ci UNION SELECT x FROM test2ci ORDER BY x;
1430 SELECT x FROM test2ci UNION SELECT x FROM test1ci ORDER BY x;
1438 SELECT x FROM test1ci INTERSECT SELECT x FROM test2ci ORDER BY x;
1445 SELECT x FROM test2ci INTERSECT SELECT x FROM test1ci ORDER BY x;
1452 SELECT x FROM test1ci EXCEPT SELECT x FROM test2ci;
1458 SELECT x FROM test2ci EXCEPT SELECT x FROM test1ci;
1463 SELECT DISTINCT x FROM test3ci ORDER BY x;
1471 SELECT count(DISTINCT x) FROM test3ci;
1477 SELECT x, count(*) FROM test3ci GROUP BY x ORDER BY x;
1485 SELECT x, row_number() OVER (ORDER BY x), rank() OVER (ORDER BY x) FROM test3ci ORDER BY x;
1486 x | row_number | rank
1487 -----+------------+------
1494 CREATE UNIQUE INDEX ON test1ci (x); -- ok
1495 INSERT INTO test1ci VALUES ('ABC'); -- error
1496 ERROR: duplicate key value violates unique constraint "test1ci_x_idx"
1497 DETAIL: Key (x)=(ABC) already exists.
1498 CREATE UNIQUE INDEX ON test3ci (x); -- error
1499 ERROR: could not create unique index "test3ci_x_idx"
1500 DETAIL: Key (x)=(abc) is duplicated.
1501 SELECT string_to_array('ABC,DEF,GHI' COLLATE case_insensitive, ',', 'abc');
1502 ERROR: nondeterministic collations are not supported for substring searches
1503 SELECT string_to_array('ABCDEFGHI' COLLATE case_insensitive, NULL, 'b');
1505 ------------------------
1506 {A,NULL,C,D,E,F,G,H,I}
1510 CREATE TABLE test1bpci (x char(3) COLLATE case_insensitive);
1511 CREATE TABLE test2bpci (x char(3) COLLATE case_insensitive);
1512 CREATE TABLE test3bpci (x char(3) COLLATE case_insensitive);
1513 CREATE INDEX ON test3bpci (x bpchar_pattern_ops); -- error
1514 ERROR: nondeterministic collations are not supported for operator class "bpchar_pattern_ops"
1515 INSERT INTO test1bpci VALUES ('abc'), ('def'), ('ghi');
1516 INSERT INTO test2bpci VALUES ('ABC'), ('ghi');
1517 INSERT INTO test3bpci VALUES ('abc'), ('ABC'), ('def'), ('ghi');
1518 SELECT x FROM test3bpci WHERE x = 'abc';
1525 SELECT x FROM test3bpci WHERE x <> 'abc';
1532 SELECT x FROM test3bpci WHERE x LIKE 'a%';
1533 ERROR: nondeterministic collations are not supported for LIKE
1534 SELECT x FROM test3bpci WHERE x ILIKE 'a%';
1535 ERROR: nondeterministic collations are not supported for ILIKE
1536 SELECT x FROM test3bpci WHERE x SIMILAR TO 'a%';
1537 ERROR: nondeterministic collations are not supported for regular expressions
1538 SELECT x FROM test3bpci WHERE x ~ 'a';
1539 ERROR: nondeterministic collations are not supported for regular expressions
1540 SELECT x FROM test1bpci UNION SELECT x FROM test2bpci ORDER BY x;
1548 SELECT x FROM test2bpci UNION SELECT x FROM test1bpci ORDER BY x;
1556 SELECT x FROM test1bpci INTERSECT SELECT x FROM test2bpci ORDER BY x;
1563 SELECT x FROM test2bpci INTERSECT SELECT x FROM test1bpci ORDER BY x;
1570 SELECT x FROM test1bpci EXCEPT SELECT x FROM test2bpci;
1576 SELECT x FROM test2bpci EXCEPT SELECT x FROM test1bpci;
1581 SELECT DISTINCT x FROM test3bpci ORDER BY x;
1589 SELECT count(DISTINCT x) FROM test3bpci;
1595 SELECT x, count(*) FROM test3bpci GROUP BY x ORDER BY x;
1603 SELECT x, row_number() OVER (ORDER BY x), rank() OVER (ORDER BY x) FROM test3bpci ORDER BY x;
1604 x | row_number | rank
1605 -----+------------+------
1612 CREATE UNIQUE INDEX ON test1bpci (x); -- ok
1613 INSERT INTO test1bpci VALUES ('ABC'); -- error
1614 ERROR: duplicate key value violates unique constraint "test1bpci_x_idx"
1615 DETAIL: Key (x)=(ABC) already exists.
1616 CREATE UNIQUE INDEX ON test3bpci (x); -- error
1617 ERROR: could not create unique index "test3bpci_x_idx"
1618 DETAIL: Key (x)=(abc) is duplicated.
1619 SELECT string_to_array('ABC,DEF,GHI'::char(11) COLLATE case_insensitive, ',', 'abc');
1620 ERROR: nondeterministic collations are not supported for substring searches
1621 SELECT string_to_array('ABCDEFGHI'::char(9) COLLATE case_insensitive, NULL, 'b');
1623 ------------------------
1624 {A,NULL,C,D,E,F,G,H,I}
1627 -- This tests the issue described in match_pattern_prefix(). In the
1628 -- absence of that check, the case_insensitive tests below would
1629 -- return no rows where they should logically return one.
1630 CREATE TABLE test4c (x text COLLATE "C");
1631 INSERT INTO test4c VALUES ('abc');
1632 CREATE INDEX ON test4c (x);
1633 SET enable_seqscan = off;
1634 SELECT x FROM test4c WHERE x LIKE 'ABC' COLLATE case_sensitive; -- ok, no rows
1639 SELECT x FROM test4c WHERE x LIKE 'ABC%' COLLATE case_sensitive; -- ok, no rows
1644 SELECT x FROM test4c WHERE x LIKE 'ABC' COLLATE case_insensitive; -- error
1645 ERROR: nondeterministic collations are not supported for LIKE
1646 SELECT x FROM test4c WHERE x LIKE 'ABC%' COLLATE case_insensitive; -- error
1647 ERROR: nondeterministic collations are not supported for LIKE
1648 RESET enable_seqscan;
1649 -- Unicode special case: different variants of Greek lower case sigma.
1650 -- A naive implementation like citext that just does lower(x) =
1651 -- lower(y) will do the wrong thing here, because lower('Σ') is 'σ'
1652 -- but upper('ς') is 'Σ'.
1653 SELECT 'ὀδυσσεύς' = 'ὈΔΥΣΣΕΎΣ' COLLATE case_sensitive;
1659 SELECT 'ὀδυσσεύς' = 'ὈΔΥΣΣΕΎΣ' COLLATE case_insensitive;
1665 -- name vs. text comparison operators
1666 SELECT relname FROM pg_class WHERE relname = 'PG_CLASS'::text COLLATE case_insensitive;
1672 SELECT relname FROM pg_class WHERE 'PG_CLASS'::text = relname COLLATE case_insensitive;
1678 SELECT typname FROM pg_type WHERE typname LIKE 'int_' AND typname <> 'INT2'::text
1679 COLLATE case_insensitive ORDER BY typname;
1686 SELECT typname FROM pg_type WHERE typname LIKE 'int_' AND 'INT2'::text <> typname
1687 COLLATE case_insensitive ORDER BY typname;
1694 -- test case adapted from subselect.sql
1695 CREATE TEMP TABLE outer_text (f1 text COLLATE case_insensitive, f2 text);
1696 INSERT INTO outer_text VALUES ('a', 'a');
1697 INSERT INTO outer_text VALUES ('b', 'a');
1698 INSERT INTO outer_text VALUES ('A', NULL);
1699 INSERT INTO outer_text VALUES ('B', NULL);
1700 CREATE TEMP TABLE inner_text (c1 text COLLATE case_insensitive, c2 text);
1701 INSERT INTO inner_text VALUES ('a', NULL);
1702 SELECT * FROM outer_text WHERE (f1, f2) NOT IN (SELECT * FROM inner_text);
1710 CREATE COLLATION ignore_accents (provider = icu, locale = '@colStrength=primary;colCaseLevel=yes', deterministic = false);
1711 CREATE TABLE test4 (a int, b text);
1712 INSERT INTO test4 VALUES (1, 'cote'), (2, 'côte'), (3, 'coté'), (4, 'côté');
1713 SELECT * FROM test4 WHERE b = 'cote';
1719 SELECT * FROM test4 WHERE b = 'cote' COLLATE ignore_accents;
1728 SELECT * FROM test4 WHERE b = 'Cote' COLLATE ignore_accents; -- still case-sensitive
1733 SELECT * FROM test4 WHERE b = 'Cote' COLLATE case_insensitive;
1739 -- foreign keys (should use collation of primary key)
1740 -- PK is case-sensitive, FK is case-insensitive
1741 CREATE TABLE test10pk (x text COLLATE case_sensitive PRIMARY KEY);
1742 INSERT INTO test10pk VALUES ('abc'), ('def'), ('ghi');
1743 CREATE TABLE test10fk (x text COLLATE case_insensitive REFERENCES test10pk (x) ON UPDATE CASCADE ON DELETE CASCADE);
1744 INSERT INTO test10fk VALUES ('abc'); -- ok
1745 INSERT INTO test10fk VALUES ('ABC'); -- error
1746 ERROR: insert or update on table "test10fk" violates foreign key constraint "test10fk_x_fkey"
1747 DETAIL: Key (x)=(ABC) is not present in table "test10pk".
1748 INSERT INTO test10fk VALUES ('xyz'); -- error
1749 ERROR: insert or update on table "test10fk" violates foreign key constraint "test10fk_x_fkey"
1750 DETAIL: Key (x)=(xyz) is not present in table "test10pk".
1751 SELECT * FROM test10pk;
1759 SELECT * FROM test10fk;
1765 -- restrict update even though the values are "equal" in the FK table
1766 UPDATE test10fk SET x = 'ABC' WHERE x = 'abc'; -- error
1767 ERROR: insert or update on table "test10fk" violates foreign key constraint "test10fk_x_fkey"
1768 DETAIL: Key (x)=(ABC) is not present in table "test10pk".
1769 SELECT * FROM test10fk;
1775 DELETE FROM test10pk WHERE x = 'abc';
1776 SELECT * FROM test10pk;
1783 SELECT * FROM test10fk;
1788 -- PK is case-insensitive, FK is case-sensitive
1789 CREATE TABLE test11pk (x text COLLATE case_insensitive PRIMARY KEY);
1790 INSERT INTO test11pk VALUES ('abc'), ('def'), ('ghi');
1791 CREATE TABLE test11fk (x text COLLATE case_sensitive REFERENCES test11pk (x) ON UPDATE CASCADE ON DELETE CASCADE);
1792 INSERT INTO test11fk VALUES ('abc'); -- ok
1793 INSERT INTO test11fk VALUES ('ABC'); -- ok
1794 INSERT INTO test11fk VALUES ('xyz'); -- error
1795 ERROR: insert or update on table "test11fk" violates foreign key constraint "test11fk_x_fkey"
1796 DETAIL: Key (x)=(xyz) is not present in table "test11pk".
1797 SELECT * FROM test11pk;
1805 SELECT * FROM test11fk;
1812 -- cascade update even though the values are "equal" in the PK table
1813 UPDATE test11pk SET x = 'ABC' WHERE x = 'abc';
1814 SELECT * FROM test11fk;
1821 DELETE FROM test11pk WHERE x = 'abc';
1822 SELECT * FROM test11pk;
1829 SELECT * FROM test11fk;
1835 CREATE TABLE test20 (a int, b text COLLATE case_insensitive) PARTITION BY LIST (b);
1836 CREATE TABLE test20_1 PARTITION OF test20 FOR VALUES IN ('abc');
1837 INSERT INTO test20 VALUES (1, 'abc');
1838 INSERT INTO test20 VALUES (2, 'ABC');
1839 SELECT * FROM test20_1;
1846 CREATE TABLE test21 (a int, b text COLLATE case_insensitive) PARTITION BY RANGE (b);
1847 CREATE TABLE test21_1 PARTITION OF test21 FOR VALUES FROM ('ABC') TO ('DEF');
1848 INSERT INTO test21 VALUES (1, 'abc');
1849 INSERT INTO test21 VALUES (2, 'ABC');
1850 SELECT * FROM test21_1;
1857 CREATE TABLE test22 (a int, b text COLLATE case_sensitive) PARTITION BY HASH (b);
1858 CREATE TABLE test22_0 PARTITION OF test22 FOR VALUES WITH (MODULUS 2, REMAINDER 0);
1859 CREATE TABLE test22_1 PARTITION OF test22 FOR VALUES WITH (MODULUS 2, REMAINDER 1);
1860 INSERT INTO test22 VALUES (1, 'def');
1861 INSERT INTO test22 VALUES (2, 'DEF');
1862 -- they end up in different partitions
1863 SELECT (SELECT count(*) FROM test22_0) = (SELECT count(*) FROM test22_1);
1870 CREATE TABLE test22a (a int, b text[] COLLATE case_sensitive) PARTITION BY HASH (b);
1871 CREATE TABLE test22a_0 PARTITION OF test22a FOR VALUES WITH (MODULUS 2, REMAINDER 0);
1872 CREATE TABLE test22a_1 PARTITION OF test22a FOR VALUES WITH (MODULUS 2, REMAINDER 1);
1873 INSERT INTO test22a VALUES (1, ARRAY['def']);
1874 INSERT INTO test22a VALUES (2, ARRAY['DEF']);
1875 -- they end up in different partitions
1876 SELECT (SELECT count(*) FROM test22a_0) = (SELECT count(*) FROM test22a_1);
1882 CREATE TABLE test23 (a int, b text COLLATE case_insensitive) PARTITION BY HASH (b);
1883 CREATE TABLE test23_0 PARTITION OF test23 FOR VALUES WITH (MODULUS 2, REMAINDER 0);
1884 CREATE TABLE test23_1 PARTITION OF test23 FOR VALUES WITH (MODULUS 2, REMAINDER 1);
1885 INSERT INTO test23 VALUES (1, 'def');
1886 INSERT INTO test23 VALUES (2, 'DEF');
1887 -- they end up in the same partition (but it's platform-dependent which one)
1888 SELECT (SELECT count(*) FROM test23_0) <> (SELECT count(*) FROM test23_1);
1895 CREATE TABLE test23a (a int, b text[] COLLATE case_insensitive) PARTITION BY HASH (b);
1896 CREATE TABLE test23a_0 PARTITION OF test23a FOR VALUES WITH (MODULUS 2, REMAINDER 0);
1897 CREATE TABLE test23a_1 PARTITION OF test23a FOR VALUES WITH (MODULUS 2, REMAINDER 1);
1898 INSERT INTO test23a VALUES (1, ARRAY['def']);
1899 INSERT INTO test23a VALUES (2, ARRAY['DEF']);
1900 -- they end up in the same partition (but it's platform-dependent which one)
1901 SELECT (SELECT count(*) FROM test23a_0) <> (SELECT count(*) FROM test23a_1);
1907 CREATE TABLE test30 (a int, b char(3) COLLATE case_insensitive) PARTITION BY LIST (b);
1908 CREATE TABLE test30_1 PARTITION OF test30 FOR VALUES IN ('abc');
1909 INSERT INTO test30 VALUES (1, 'abc');
1910 INSERT INTO test30 VALUES (2, 'ABC');
1911 SELECT * FROM test30_1;
1918 CREATE TABLE test31 (a int, b char(3) COLLATE case_insensitive) PARTITION BY RANGE (b);
1919 CREATE TABLE test31_1 PARTITION OF test31 FOR VALUES FROM ('ABC') TO ('DEF');
1920 INSERT INTO test31 VALUES (1, 'abc');
1921 INSERT INTO test31 VALUES (2, 'ABC');
1922 SELECT * FROM test31_1;
1929 CREATE TABLE test32 (a int, b char(3) COLLATE case_sensitive) PARTITION BY HASH (b);
1930 CREATE TABLE test32_0 PARTITION OF test32 FOR VALUES WITH (MODULUS 2, REMAINDER 0);
1931 CREATE TABLE test32_1 PARTITION OF test32 FOR VALUES WITH (MODULUS 2, REMAINDER 1);
1932 INSERT INTO test32 VALUES (1, 'def');
1933 INSERT INTO test32 VALUES (2, 'DEF');
1934 -- they end up in different partitions
1935 SELECT (SELECT count(*) FROM test32_0) = (SELECT count(*) FROM test32_1);
1941 CREATE TABLE test33 (a int, b char(3) COLLATE case_insensitive) PARTITION BY HASH (b);
1942 CREATE TABLE test33_0 PARTITION OF test33 FOR VALUES WITH (MODULUS 2, REMAINDER 0);
1943 CREATE TABLE test33_1 PARTITION OF test33 FOR VALUES WITH (MODULUS 2, REMAINDER 1);
1944 INSERT INTO test33 VALUES (1, 'def');
1945 INSERT INTO test33 VALUES (2, 'DEF');
1946 -- they end up in the same partition (but it's platform-dependent which one)
1947 SELECT (SELECT count(*) FROM test33_0) <> (SELECT count(*) FROM test33_1);
1955 SET client_min_messages TO warning;
1956 DROP SCHEMA collate_tests CASCADE;
1957 RESET client_min_messages;
1958 -- leave a collation for pg_upgrade test
1959 CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";