2 -- Test citext datatype
4 CREATE EXTENSION citext;
5 -- Check whether any of our opclasses fail amvalidate
7 FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
8 WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
13 -- Test the operators and indexing functions
15 SELECT 'a'::citext = 'a'::citext AS t;
21 SELECT 'a'::citext = 'A'::citext AS t;
27 SELECT 'a'::citext = 'A'::text AS f; -- text wins the discussion
33 SELECT 'a'::citext = 'b'::citext AS f;
39 SELECT 'a'::citext = 'ab'::citext AS f;
45 SELECT 'a'::citext <> 'ab'::citext AS t;
52 SELECT 'B'::citext > 'a'::citext AS t;
58 SELECT 'b'::citext > 'A'::citext AS t;
64 SELECT 'B'::citext > 'b'::citext AS f;
70 SELECT 'B'::citext >= 'b'::citext AS t;
77 SELECT 'a'::citext < 'B'::citext AS t;
83 SELECT 'a'::citext <= 'B'::citext AS t;
89 -- Test implicit casting. citext casts to text, but not vice-versa.
90 SELECT 'a'::citext = 'a'::text AS t;
96 SELECT 'A'::text <> 'a'::citext AS t;
102 SELECT 'B'::citext < 'a'::text AS t; -- text wins.
108 SELECT 'B'::citext <= 'a'::text AS t; -- text wins.
114 SELECT 'a'::citext > 'B'::text AS t; -- text wins.
120 SELECT 'a'::citext >= 'B'::text AS t; -- text wins.
126 -- Test implicit casting. citext casts to varchar, but not vice-versa.
127 SELECT 'a'::citext = 'a'::varchar AS t;
133 SELECT 'A'::varchar <> 'a'::citext AS t;
139 SELECT 'B'::citext < 'a'::varchar AS t; -- varchar wins.
145 SELECT 'B'::citext <= 'a'::varchar AS t; -- varchar wins.
151 SELECT 'a'::citext > 'B'::varchar AS t; -- varchar wins.
157 SELECT 'a'::citext >= 'B'::varchar AS t; -- varchar wins.
163 -- A couple of longer examples to ensure that we don't get any issues with bad
164 -- conversions to char[] in the c code. Yes, I did do this.
165 SELECT 'aardvark'::citext = 'aardvark'::citext AS t;
171 SELECT 'aardvark'::citext = 'aardVark'::citext AS t;
177 -- Check the citext_cmp() function explicitly.
178 SELECT citext_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
184 SELECT citext_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
190 SELECT citext_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
196 SELECT citext_cmp('B'::citext, 'a'::citext) > 0 AS true;
202 -- Check the citext_hash() and citext_hash_extended() function explicitly.
203 SELECT v as value, citext_hash(v)::bit(32) as standard,
204 citext_hash_extended(v, 0)::bit(32) as extended0,
205 citext_hash_extended(v, 1)::bit(32) as extended1
206 FROM (VALUES (NULL::citext), ('PostgreSQL'), ('eIpUEtqmY89'), ('AXKEJBTK'),
207 ('muop28x03'), ('yi3nm0d73')) x(v)
208 WHERE citext_hash(v)::bit(32) != citext_hash_extended(v, 0)::bit(32)
209 OR citext_hash(v)::bit(32) = citext_hash_extended(v, 1)::bit(32);
210 value | standard | extended0 | extended1
211 -------+----------+-----------+-----------
214 -- Do some tests using a table and index.
215 CREATE TEMP TABLE try (
216 name citext PRIMARY KEY
218 INSERT INTO try (name)
219 VALUES ('a'), ('ab'), ('â'), ('aba'), ('b'), ('ba'), ('bab'), ('AZ');
220 SELECT name, 'a' = name AS eq_a FROM try WHERE name <> 'â';
232 SELECT name, 'a' = name AS t FROM try where name = 'a';
238 SELECT name, 'A' = name AS "eq_A" FROM try WHERE name <> 'â';
250 SELECT name, 'A' = name AS t FROM try where name = 'A';
256 SELECT name, 'A' = name AS t FROM try where name = 'A';
262 -- expected failures on duplicate key
263 INSERT INTO try (name) VALUES ('a');
264 ERROR: duplicate key value violates unique constraint "try_pkey"
265 DETAIL: Key (name)=(a) already exists.
266 INSERT INTO try (name) VALUES ('A');
267 ERROR: duplicate key value violates unique constraint "try_pkey"
268 DETAIL: Key (name)=(A) already exists.
269 INSERT INTO try (name) VALUES ('aB');
270 ERROR: duplicate key value violates unique constraint "try_pkey"
271 DETAIL: Key (name)=(aB) already exists.
272 -- Make sure that citext_smaller() and citext_larger() work properly.
273 SELECT citext_smaller( 'ab'::citext, 'ac'::citext ) = 'ab' AS t;
279 SELECT citext_smaller( 'ABC'::citext, 'bbbb'::citext ) = 'ABC' AS t;
285 SELECT citext_smaller( 'aardvark'::citext, 'Aaba'::citext ) = 'Aaba' AS t;
291 SELECT citext_smaller( 'aardvark'::citext, 'AARDVARK'::citext ) = 'AARDVARK' AS t;
297 SELECT citext_larger( 'ab'::citext, 'ac'::citext ) = 'ac' AS t;
303 SELECT citext_larger( 'ABC'::citext, 'bbbb'::citext ) = 'bbbb' AS t;
309 SELECT citext_larger( 'aardvark'::citext, 'Aaba'::citext ) = 'aardvark' AS t;
315 -- Test aggregate functions and sort ordering
316 CREATE TEMP TABLE srt (
319 INSERT INTO srt (name)
324 CREATE INDEX srt_name ON srt (name);
325 -- Check the min() and max() aggregates, with and without index.
326 set enable_seqscan = off;
327 SELECT MIN(name) AS "ABA" FROM srt;
333 SELECT MAX(name) AS abd FROM srt;
339 reset enable_seqscan;
340 set enable_indexscan = off;
341 SELECT MIN(name) AS "ABA" FROM srt;
347 SELECT MAX(name) AS abd FROM srt;
353 reset enable_indexscan;
354 -- Check sorting likewise
355 set enable_seqscan = off;
356 SELECT name FROM srt ORDER BY name;
365 reset enable_seqscan;
366 set enable_indexscan = off;
367 SELECT name FROM srt ORDER BY name;
376 reset enable_indexscan;
377 -- Test assignment casts.
378 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::text;
384 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::varchar;
390 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::bpchar;
396 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA';
402 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::citext;
408 -- LIKE should be case-insensitive
409 SELECT name FROM srt WHERE name LIKE '%a%' ORDER BY name;
418 SELECT name FROM srt WHERE name NOT LIKE '%b%' ORDER BY name;
423 SELECT name FROM srt WHERE name LIKE '%A%' ORDER BY name;
432 SELECT name FROM srt WHERE name NOT LIKE '%B%' ORDER BY name;
437 -- ~~ should be case-insensitive
438 SELECT name FROM srt WHERE name ~~ '%a%' ORDER BY name;
447 SELECT name FROM srt WHERE name !~~ '%b%' ORDER BY name;
452 SELECT name FROM srt WHERE name ~~ '%A%' ORDER BY name;
461 SELECT name FROM srt WHERE name !~~ '%B%' ORDER BY name;
466 -- ~ should be case-insensitive
467 SELECT name FROM srt WHERE name ~ '^a' ORDER BY name;
476 SELECT name FROM srt WHERE name !~ 'a$' ORDER BY name;
484 SELECT name FROM srt WHERE name ~ '^A' ORDER BY name;
493 SELECT name FROM srt WHERE name !~ 'A$' ORDER BY name;
501 -- SIMILAR TO should be case-insensitive.
502 SELECT name FROM srt WHERE name SIMILAR TO '%a.*';
508 SELECT name FROM srt WHERE name SIMILAR TO '%A.*';
515 SELECT true::citext = 'true' AS t;
521 SELECT 'true'::citext::boolean = true AS t;
527 SELECT 4::citext = '4' AS t;
533 SELECT 4::int4::citext = '4' AS t;
539 SELECT '4'::citext::int4 = 4 AS t;
545 SELECT 4::integer::citext = '4' AS t;
551 SELECT '4'::citext::integer = 4 AS t;
557 SELECT 4::int8::citext = '4' AS t;
563 SELECT '4'::citext::int8 = 4 AS t;
569 SELECT 4::bigint::citext = '4' AS t;
575 SELECT '4'::citext::bigint = 4 AS t;
581 SELECT 4::int2::citext = '4' AS t;
587 SELECT '4'::citext::int2 = 4 AS t;
593 SELECT 4::smallint::citext = '4' AS t;
599 SELECT '4'::citext::smallint = 4 AS t;
605 SELECT 4.0::numeric = '4.0' AS t;
611 SELECT '4.0'::citext::numeric = 4.0 AS t;
617 SELECT 4.0::decimal = '4.0' AS t;
623 SELECT '4.0'::citext::decimal = 4.0 AS t;
629 SELECT 4.0::real = '4.0' AS t;
635 SELECT '4.0'::citext::real = 4.0 AS t;
641 SELECT 4.0::float4 = '4.0' AS t;
647 SELECT '4.0'::citext::float4 = 4.0 AS t;
653 SELECT 4.0::double precision = '4.0' AS t;
659 SELECT '4.0'::citext::double precision = 4.0 AS t;
665 SELECT 4.0::float8 = '4.0' AS t;
671 SELECT '4.0'::citext::float8 = 4.0 AS t;
677 SELECT 'foo'::name::citext = 'foo' AS t;
683 SELECT 'foo'::citext::name = 'foo'::name AS t;
689 SELECT 'f'::char::citext = 'f' AS t;
695 SELECT 'f'::citext::char = 'f'::char AS t;
701 SELECT 'f'::"char"::citext = 'f' AS t;
707 SELECT 'f'::citext::"char" = 'f'::"char" AS t;
713 SELECT '100'::money::citext = '$100.00' AS t;
719 SELECT '100'::citext::money = '100'::money AS t;
725 SELECT 'a'::char::citext = 'a' AS t;
731 SELECT 'a'::citext::char = 'a'::char AS t;
737 SELECT 'foo'::varchar::citext = 'foo' AS t;
743 SELECT 'foo'::citext::varchar = 'foo'::varchar AS t;
749 SELECT 'foo'::text::citext = 'foo' AS t;
755 SELECT 'foo'::citext::text = 'foo'::text AS t;
761 SELECT '192.168.100.128/25'::cidr::citext = '192.168.100.128/25' AS t;
767 SELECT '192.168.100.128/25'::citext::cidr = '192.168.100.128/25'::cidr AS t;
773 SELECT '192.168.100.128'::inet::citext = '192.168.100.128/32' AS t;
779 SELECT '192.168.100.128'::citext::inet = '192.168.100.128'::inet AS t;
785 SELECT '08:00:2b:01:02:03'::macaddr::citext = '08:00:2b:01:02:03' AS t;
791 SELECT '08:00:2b:01:02:03'::citext::macaddr = '08:00:2b:01:02:03'::macaddr AS t;
797 SELECT '1999-01-08 04:05:06'::timestamp::citext = '1999-01-08 04:05:06'::timestamp::text AS t;
803 SELECT '1999-01-08 04:05:06'::citext::timestamp = '1999-01-08 04:05:06'::timestamp AS t;
809 SELECT '1999-01-08 04:05:06'::timestamptz::citext = '1999-01-08 04:05:06'::timestamptz::text AS t;
815 SELECT '1999-01-08 04:05:06'::citext::timestamptz = '1999-01-08 04:05:06'::timestamptz AS t;
821 SELECT '1 hour'::interval::citext = '1 hour'::interval::text AS t;
827 SELECT '1 hour'::citext::interval = '1 hour'::interval AS t;
833 SELECT '1999-01-08'::date::citext = '1999-01-08'::date::text AS t;
839 SELECT '1999-01-08'::citext::date = '1999-01-08'::date AS t;
845 SELECT '04:05:06'::time::citext = '04:05:06' AS t;
851 SELECT '04:05:06'::citext::time = '04:05:06'::time AS t;
857 SELECT '04:05:06'::timetz::citext = '04:05:06'::timetz::text AS t;
863 SELECT '04:05:06'::citext::timetz = '04:05:06'::timetz AS t;
869 SELECT '( 1 , 1)'::point::citext = '(1,1)' AS t;
875 SELECT '( 1 , 1)'::citext::point ~= '(1,1)'::point AS t;
881 SELECT '( 1 , 1 ) , ( 2 , 2 )'::lseg::citext = '[(1,1),(2,2)]' AS t;
887 SELECT '( 1 , 1 ) , ( 2 , 2 )'::citext::lseg = '[(1,1),(2,2)]'::lseg AS t;
893 SELECT '( 0 , 0 ) , ( 1 , 1 )'::box::citext = '(0,0),(1,1)'::box::text AS t;
899 SELECT '( 0 , 0 ) , ( 1 , 1 )'::citext::box ~= '(0,0),(1,1)'::text::box AS t;
905 SELECT '((0,0),(1,1),(2,0))'::path::citext = '((0,0),(1,1),(2,0))' AS t;
911 SELECT '((0,0),(1,1),(2,0))'::citext::path = '((0,0),(1,1),(2,0))'::path AS t;
917 SELECT '((0,0),(1,1))'::polygon::citext = '((0,0),(1,1))' AS t;
923 SELECT '((0,0),(1,1))'::citext::polygon ~= '((0,0),(1,1))'::polygon AS t;
929 SELECT '((0,0),2)'::circle::citext = '((0,0),2)'::circle::text AS t;
935 SELECT '((0,0),2)'::citext::circle ~= '((0,0),2)'::text::circle AS t;
941 SELECT '101'::bit::citext = '101'::bit::text AS t;
947 SELECT '101'::citext::bit = '101'::text::bit AS t;
953 SELECT '101'::bit varying::citext = '101'::bit varying::text AS t;
959 SELECT '101'::citext::bit varying = '101'::text::bit varying AS t;
965 SELECT 'a fat cat'::tsvector::citext = '''a'' ''cat'' ''fat''' AS t;
971 SELECT 'a fat cat'::citext::tsvector = 'a fat cat'::tsvector AS t;
977 SELECT 'fat & rat'::tsquery::citext = '''fat'' & ''rat''' AS t;
983 SELECT 'fat & rat'::citext::tsquery = 'fat & rat'::tsquery AS t;
989 SELECT 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid::citext = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' AS t;
995 SELECT 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::citext::uuid = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid AS t;
1001 CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
1002 SELECT 'sad'::mood::citext = 'sad' AS t;
1008 SELECT 'sad'::citext::mood = 'sad'::mood AS t;
1014 -- Assignment casts.
1015 CREATE TABLE caster (
1035 timestamp timestamp,
1036 timestamptz timestamptz,
1053 INSERT INTO caster (text) VALUES ('foo'::citext);
1054 INSERT INTO caster (citext) VALUES ('foo'::text);
1055 INSERT INTO caster (varchar) VALUES ('foo'::text);
1056 INSERT INTO caster (text) VALUES ('foo'::varchar);
1057 INSERT INTO caster (varchar) VALUES ('foo'::citext);
1058 INSERT INTO caster (citext) VALUES ('foo'::varchar);
1059 INSERT INTO caster (bpchar) VALUES ('foo'::text);
1060 INSERT INTO caster (text) VALUES ('foo'::bpchar);
1061 INSERT INTO caster (bpchar) VALUES ('foo'::citext);
1062 INSERT INTO caster (citext) VALUES ('foo'::bpchar);
1063 INSERT INTO caster (char) VALUES ('f'::text);
1064 INSERT INTO caster (text) VALUES ('f'::char);
1065 INSERT INTO caster (char) VALUES ('f'::citext);
1066 INSERT INTO caster (citext) VALUES ('f'::char);
1067 INSERT INTO caster (chr) VALUES ('f'::text);
1068 INSERT INTO caster (text) VALUES ('f'::"char");
1069 INSERT INTO caster (chr) VALUES ('f'::citext); -- requires cast
1070 ERROR: column "chr" is of type "char" but expression is of type citext
1071 LINE 1: INSERT INTO caster (chr) VALUES ('f'::citext);
1073 HINT: You will need to rewrite or cast the expression.
1074 INSERT INTO caster (chr) VALUES ('f'::citext::text);
1075 INSERT INTO caster (citext) VALUES ('f'::"char");
1076 INSERT INTO caster (name) VALUES ('foo'::text);
1077 INSERT INTO caster (text) VALUES ('foo'::name);
1078 INSERT INTO caster (name) VALUES ('foo'::citext);
1079 INSERT INTO caster (citext) VALUES ('foo'::name);
1080 -- Cannot cast to bytea on assignment.
1081 INSERT INTO caster (bytea) VALUES ('foo'::text);
1082 ERROR: column "bytea" is of type bytea but expression is of type text
1083 LINE 1: INSERT INTO caster (bytea) VALUES ('foo'::text);
1085 HINT: You will need to rewrite or cast the expression.
1086 INSERT INTO caster (text) VALUES ('foo'::bytea);
1087 INSERT INTO caster (bytea) VALUES ('foo'::citext);
1088 ERROR: column "bytea" is of type bytea but expression is of type citext
1089 LINE 1: INSERT INTO caster (bytea) VALUES ('foo'::citext);
1091 HINT: You will need to rewrite or cast the expression.
1092 INSERT INTO caster (citext) VALUES ('foo'::bytea);
1093 -- Cannot cast to boolean on assignment.
1094 INSERT INTO caster (boolean) VALUES ('t'::text);
1095 ERROR: column "boolean" is of type boolean but expression is of type text
1096 LINE 1: INSERT INTO caster (boolean) VALUES ('t'::text);
1098 HINT: You will need to rewrite or cast the expression.
1099 INSERT INTO caster (text) VALUES ('t'::boolean);
1100 INSERT INTO caster (boolean) VALUES ('t'::citext);
1101 ERROR: column "boolean" is of type boolean but expression is of type citext
1102 LINE 1: INSERT INTO caster (boolean) VALUES ('t'::citext);
1104 HINT: You will need to rewrite or cast the expression.
1105 INSERT INTO caster (citext) VALUES ('t'::boolean);
1106 -- Cannot cast to float8 on assignment.
1107 INSERT INTO caster (float8) VALUES ('12.42'::text);
1108 ERROR: column "float8" is of type double precision but expression is of type text
1109 LINE 1: INSERT INTO caster (float8) VALUES ('12.42'::text);
1111 HINT: You will need to rewrite or cast the expression.
1112 INSERT INTO caster (text) VALUES ('12.42'::float8);
1113 INSERT INTO caster (float8) VALUES ('12.42'::citext);
1114 ERROR: column "float8" is of type double precision but expression is of type citext
1115 LINE 1: INSERT INTO caster (float8) VALUES ('12.42'::citext);
1117 HINT: You will need to rewrite or cast the expression.
1118 INSERT INTO caster (citext) VALUES ('12.42'::float8);
1119 -- Cannot cast to float4 on assignment.
1120 INSERT INTO caster (float4) VALUES ('12.42'::text);
1121 ERROR: column "float4" is of type real but expression is of type text
1122 LINE 1: INSERT INTO caster (float4) VALUES ('12.42'::text);
1124 HINT: You will need to rewrite or cast the expression.
1125 INSERT INTO caster (text) VALUES ('12.42'::float4);
1126 INSERT INTO caster (float4) VALUES ('12.42'::citext);
1127 ERROR: column "float4" is of type real but expression is of type citext
1128 LINE 1: INSERT INTO caster (float4) VALUES ('12.42'::citext);
1130 HINT: You will need to rewrite or cast the expression.
1131 INSERT INTO caster (citext) VALUES ('12.42'::float4);
1132 -- Cannot cast to numeric on assignment.
1133 INSERT INTO caster (numeric) VALUES ('12.42'::text);
1134 ERROR: column "numeric" is of type numeric but expression is of type text
1135 LINE 1: INSERT INTO caster (numeric) VALUES ('12.42'::text);
1137 HINT: You will need to rewrite or cast the expression.
1138 INSERT INTO caster (text) VALUES ('12.42'::numeric);
1139 INSERT INTO caster (numeric) VALUES ('12.42'::citext);
1140 ERROR: column "numeric" is of type numeric but expression is of type citext
1141 LINE 1: INSERT INTO caster (numeric) VALUES ('12.42'::citext);
1143 HINT: You will need to rewrite or cast the expression.
1144 INSERT INTO caster (citext) VALUES ('12.42'::numeric);
1145 -- Cannot cast to int8 on assignment.
1146 INSERT INTO caster (int8) VALUES ('12'::text);
1147 ERROR: column "int8" is of type bigint but expression is of type text
1148 LINE 1: INSERT INTO caster (int8) VALUES ('12'::text);
1150 HINT: You will need to rewrite or cast the expression.
1151 INSERT INTO caster (text) VALUES ('12'::int8);
1152 INSERT INTO caster (int8) VALUES ('12'::citext);
1153 ERROR: column "int8" is of type bigint but expression is of type citext
1154 LINE 1: INSERT INTO caster (int8) VALUES ('12'::citext);
1156 HINT: You will need to rewrite or cast the expression.
1157 INSERT INTO caster (citext) VALUES ('12'::int8);
1158 -- Cannot cast to int4 on assignment.
1159 INSERT INTO caster (int4) VALUES ('12'::text);
1160 ERROR: column "int4" is of type integer but expression is of type text
1161 LINE 1: INSERT INTO caster (int4) VALUES ('12'::text);
1163 HINT: You will need to rewrite or cast the expression.
1164 INSERT INTO caster (text) VALUES ('12'::int4);
1165 INSERT INTO caster (int4) VALUES ('12'::citext);
1166 ERROR: column "int4" is of type integer but expression is of type citext
1167 LINE 1: INSERT INTO caster (int4) VALUES ('12'::citext);
1169 HINT: You will need to rewrite or cast the expression.
1170 INSERT INTO caster (citext) VALUES ('12'::int4);
1171 -- Cannot cast to int2 on assignment.
1172 INSERT INTO caster (int2) VALUES ('12'::text);
1173 ERROR: column "int2" is of type smallint but expression is of type text
1174 LINE 1: INSERT INTO caster (int2) VALUES ('12'::text);
1176 HINT: You will need to rewrite or cast the expression.
1177 INSERT INTO caster (text) VALUES ('12'::int2);
1178 INSERT INTO caster (int2) VALUES ('12'::citext);
1179 ERROR: column "int2" is of type smallint but expression is of type citext
1180 LINE 1: INSERT INTO caster (int2) VALUES ('12'::citext);
1182 HINT: You will need to rewrite or cast the expression.
1183 INSERT INTO caster (citext) VALUES ('12'::int2);
1184 -- Cannot cast to cidr on assignment.
1185 INSERT INTO caster (cidr) VALUES ('192.168.100.128/25'::text);
1186 ERROR: column "cidr" is of type cidr but expression is of type text
1187 LINE 1: INSERT INTO caster (cidr) VALUES ('192.168.100.128/...
1189 HINT: You will need to rewrite or cast the expression.
1190 INSERT INTO caster (text) VALUES ('192.168.100.128/25'::cidr);
1191 INSERT INTO caster (cidr) VALUES ('192.168.100.128/25'::citext);
1192 ERROR: column "cidr" is of type cidr but expression is of type citext
1193 LINE 1: INSERT INTO caster (cidr) VALUES ('192.168.100.128/...
1195 HINT: You will need to rewrite or cast the expression.
1196 INSERT INTO caster (citext) VALUES ('192.168.100.128/25'::cidr);
1197 -- Cannot cast to inet on assignment.
1198 INSERT INTO caster (inet) VALUES ('192.168.100.128'::text);
1199 ERROR: column "inet" is of type inet but expression is of type text
1200 LINE 1: INSERT INTO caster (inet) VALUES ('192.168.100.128'...
1202 HINT: You will need to rewrite or cast the expression.
1203 INSERT INTO caster (text) VALUES ('192.168.100.128'::inet);
1204 INSERT INTO caster (inet) VALUES ('192.168.100.128'::citext);
1205 ERROR: column "inet" is of type inet but expression is of type citext
1206 LINE 1: INSERT INTO caster (inet) VALUES ('192.168.100.128'...
1208 HINT: You will need to rewrite or cast the expression.
1209 INSERT INTO caster (citext) VALUES ('192.168.100.128'::inet);
1210 -- Cannot cast to macaddr on assignment.
1211 INSERT INTO caster (macaddr) VALUES ('08:00:2b:01:02:03'::text);
1212 ERROR: column "macaddr" is of type macaddr but expression is of type text
1213 LINE 1: INSERT INTO caster (macaddr) VALUES ('08:00:2b:01:02:0...
1215 HINT: You will need to rewrite or cast the expression.
1216 INSERT INTO caster (text) VALUES ('08:00:2b:01:02:03'::macaddr);
1217 INSERT INTO caster (macaddr) VALUES ('08:00:2b:01:02:03'::citext);
1218 ERROR: column "macaddr" is of type macaddr but expression is of type citext
1219 LINE 1: INSERT INTO caster (macaddr) VALUES ('08:00:2b:01:02:0...
1221 HINT: You will need to rewrite or cast the expression.
1222 INSERT INTO caster (citext) VALUES ('08:00:2b:01:02:03'::macaddr);
1223 -- Cannot cast to money on assignment.
1224 INSERT INTO caster (money) VALUES ('12'::text);
1225 ERROR: column "money" is of type money but expression is of type text
1226 LINE 1: INSERT INTO caster (money) VALUES ('12'::text);
1228 HINT: You will need to rewrite or cast the expression.
1229 INSERT INTO caster (text) VALUES ('12'::money);
1230 INSERT INTO caster (money) VALUES ('12'::citext);
1231 ERROR: column "money" is of type money but expression is of type citext
1232 LINE 1: INSERT INTO caster (money) VALUES ('12'::citext);
1234 HINT: You will need to rewrite or cast the expression.
1235 INSERT INTO caster (citext) VALUES ('12'::money);
1236 -- Cannot cast to timestamp on assignment.
1237 INSERT INTO caster (timestamp) VALUES ('1999-01-08 04:05:06'::text);
1238 ERROR: column "timestamp" is of type timestamp without time zone but expression is of type text
1239 LINE 1: INSERT INTO caster (timestamp) VALUES ('1999-01-08 04:05...
1241 HINT: You will need to rewrite or cast the expression.
1242 INSERT INTO caster (text) VALUES ('1999-01-08 04:05:06'::timestamp);
1243 INSERT INTO caster (timestamp) VALUES ('1999-01-08 04:05:06'::citext);
1244 ERROR: column "timestamp" is of type timestamp without time zone but expression is of type citext
1245 LINE 1: INSERT INTO caster (timestamp) VALUES ('1999-01-08 04:05...
1247 HINT: You will need to rewrite or cast the expression.
1248 INSERT INTO caster (citext) VALUES ('1999-01-08 04:05:06'::timestamp);
1249 -- Cannot cast to timestamptz on assignment.
1250 INSERT INTO caster (timestamptz) VALUES ('1999-01-08 04:05:06'::text);
1251 ERROR: column "timestamptz" is of type timestamp with time zone but expression is of type text
1252 LINE 1: INSERT INTO caster (timestamptz) VALUES ('1999-01-08 04:05...
1254 HINT: You will need to rewrite or cast the expression.
1255 INSERT INTO caster (text) VALUES ('1999-01-08 04:05:06'::timestamptz);
1256 INSERT INTO caster (timestamptz) VALUES ('1999-01-08 04:05:06'::citext);
1257 ERROR: column "timestamptz" is of type timestamp with time zone but expression is of type citext
1258 LINE 1: INSERT INTO caster (timestamptz) VALUES ('1999-01-08 04:05...
1260 HINT: You will need to rewrite or cast the expression.
1261 INSERT INTO caster (citext) VALUES ('1999-01-08 04:05:06'::timestamptz);
1262 -- Cannot cast to interval on assignment.
1263 INSERT INTO caster (interval) VALUES ('1 hour'::text);
1264 ERROR: column "interval" is of type interval but expression is of type text
1265 LINE 1: INSERT INTO caster (interval) VALUES ('1 hour'::text);
1267 HINT: You will need to rewrite or cast the expression.
1268 INSERT INTO caster (text) VALUES ('1 hour'::interval);
1269 INSERT INTO caster (interval) VALUES ('1 hour'::citext);
1270 ERROR: column "interval" is of type interval but expression is of type citext
1271 LINE 1: INSERT INTO caster (interval) VALUES ('1 hour'::citext)...
1273 HINT: You will need to rewrite or cast the expression.
1274 INSERT INTO caster (citext) VALUES ('1 hour'::interval);
1275 -- Cannot cast to date on assignment.
1276 INSERT INTO caster (date) VALUES ('1999-01-08'::text);
1277 ERROR: column "date" is of type date but expression is of type text
1278 LINE 1: INSERT INTO caster (date) VALUES ('1999-01-08'::tex...
1280 HINT: You will need to rewrite or cast the expression.
1281 INSERT INTO caster (text) VALUES ('1999-01-08'::date);
1282 INSERT INTO caster (date) VALUES ('1999-01-08'::citext);
1283 ERROR: column "date" is of type date but expression is of type citext
1284 LINE 1: INSERT INTO caster (date) VALUES ('1999-01-08'::cit...
1286 HINT: You will need to rewrite or cast the expression.
1287 INSERT INTO caster (citext) VALUES ('1999-01-08'::date);
1288 -- Cannot cast to time on assignment.
1289 INSERT INTO caster (time) VALUES ('04:05:06'::text);
1290 ERROR: column "time" is of type time without time zone but expression is of type text
1291 LINE 1: INSERT INTO caster (time) VALUES ('04:05:06'::text)...
1293 HINT: You will need to rewrite or cast the expression.
1294 INSERT INTO caster (text) VALUES ('04:05:06'::time);
1295 INSERT INTO caster (time) VALUES ('04:05:06'::citext);
1296 ERROR: column "time" is of type time without time zone but expression is of type citext
1297 LINE 1: INSERT INTO caster (time) VALUES ('04:05:06'::citex...
1299 HINT: You will need to rewrite or cast the expression.
1300 INSERT INTO caster (citext) VALUES ('04:05:06'::time);
1301 -- Cannot cast to timetz on assignment.
1302 INSERT INTO caster (timetz) VALUES ('04:05:06'::text);
1303 ERROR: column "timetz" is of type time with time zone but expression is of type text
1304 LINE 1: INSERT INTO caster (timetz) VALUES ('04:05:06'::text)...
1306 HINT: You will need to rewrite or cast the expression.
1307 INSERT INTO caster (text) VALUES ('04:05:06'::timetz);
1308 INSERT INTO caster (timetz) VALUES ('04:05:06'::citext);
1309 ERROR: column "timetz" is of type time with time zone but expression is of type citext
1310 LINE 1: INSERT INTO caster (timetz) VALUES ('04:05:06'::citex...
1312 HINT: You will need to rewrite or cast the expression.
1313 INSERT INTO caster (citext) VALUES ('04:05:06'::timetz);
1314 -- Cannot cast to point on assignment.
1315 INSERT INTO caster (point) VALUES ('( 1 , 1)'::text);
1316 ERROR: column "point" is of type point but expression is of type text
1317 LINE 1: INSERT INTO caster (point) VALUES ('( 1 , 1)'::text)...
1319 HINT: You will need to rewrite or cast the expression.
1320 INSERT INTO caster (text) VALUES ('( 1 , 1)'::point);
1321 INSERT INTO caster (point) VALUES ('( 1 , 1)'::citext);
1322 ERROR: column "point" is of type point but expression is of type citext
1323 LINE 1: INSERT INTO caster (point) VALUES ('( 1 , 1)'::citex...
1325 HINT: You will need to rewrite or cast the expression.
1326 INSERT INTO caster (citext) VALUES ('( 1 , 1)'::point);
1327 -- Cannot cast to lseg on assignment.
1328 INSERT INTO caster (lseg) VALUES ('( 1 , 1 ) , ( 2 , 2 )'::text);
1329 ERROR: column "lseg" is of type lseg but expression is of type text
1330 LINE 1: INSERT INTO caster (lseg) VALUES ('( 1 , 1 ) , ( 2 ...
1332 HINT: You will need to rewrite or cast the expression.
1333 INSERT INTO caster (text) VALUES ('( 1 , 1 ) , ( 2 , 2 )'::lseg);
1334 INSERT INTO caster (lseg) VALUES ('( 1 , 1 ) , ( 2 , 2 )'::citext);
1335 ERROR: column "lseg" is of type lseg but expression is of type citext
1336 LINE 1: INSERT INTO caster (lseg) VALUES ('( 1 , 1 ) , ( 2 ...
1338 HINT: You will need to rewrite or cast the expression.
1339 INSERT INTO caster (citext) VALUES ('( 1 , 1 ) , ( 2 , 2 )'::lseg);
1340 -- Cannot cast to box on assignment.
1341 INSERT INTO caster (box) VALUES ('(0,0),(1,1)'::text);
1342 ERROR: column "box" is of type box but expression is of type text
1343 LINE 1: INSERT INTO caster (box) VALUES ('(0,0),(1,1)'::te...
1345 HINT: You will need to rewrite or cast the expression.
1346 INSERT INTO caster (text) VALUES ('(0,0),(1,1)'::box);
1347 INSERT INTO caster (box) VALUES ('(0,0),(1,1)'::citext);
1348 ERROR: column "box" is of type box but expression is of type citext
1349 LINE 1: INSERT INTO caster (box) VALUES ('(0,0),(1,1)'::ci...
1351 HINT: You will need to rewrite or cast the expression.
1352 INSERT INTO caster (citext) VALUES ('(0,0),(1,1)'::box);
1353 -- Cannot cast to path on assignment.
1354 INSERT INTO caster (path) VALUES ('((0,0),(1,1),(2,0))'::text);
1355 ERROR: column "path" is of type path but expression is of type text
1356 LINE 1: INSERT INTO caster (path) VALUES ('((0,0),(1,1),(2,...
1358 HINT: You will need to rewrite or cast the expression.
1359 INSERT INTO caster (text) VALUES ('((0,0),(1,1),(2,0))'::path);
1360 INSERT INTO caster (path) VALUES ('((0,0),(1,1),(2,0))'::citext);
1361 ERROR: column "path" is of type path but expression is of type citext
1362 LINE 1: INSERT INTO caster (path) VALUES ('((0,0),(1,1),(2,...
1364 HINT: You will need to rewrite or cast the expression.
1365 INSERT INTO caster (citext) VALUES ('((0,0),(1,1),(2,0))'::path);
1366 -- Cannot cast to polygon on assignment.
1367 INSERT INTO caster (polygon) VALUES ('((0,0),(1,1))'::text);
1368 ERROR: column "polygon" is of type polygon but expression is of type text
1369 LINE 1: INSERT INTO caster (polygon) VALUES ('((0,0),(1,1))'::...
1371 HINT: You will need to rewrite or cast the expression.
1372 INSERT INTO caster (text) VALUES ('((0,0),(1,1))'::polygon);
1373 INSERT INTO caster (polygon) VALUES ('((0,0),(1,1))'::citext);
1374 ERROR: column "polygon" is of type polygon but expression is of type citext
1375 LINE 1: INSERT INTO caster (polygon) VALUES ('((0,0),(1,1))'::...
1377 HINT: You will need to rewrite or cast the expression.
1378 INSERT INTO caster (citext) VALUES ('((0,0),(1,1))'::polygon);
1379 -- Cannot cast to circle on assignment.
1380 INSERT INTO caster (circle) VALUES ('((0,0),2)'::text);
1381 ERROR: column "circle" is of type circle but expression is of type text
1382 LINE 1: INSERT INTO caster (circle) VALUES ('((0,0),2)'::text...
1384 HINT: You will need to rewrite or cast the expression.
1385 INSERT INTO caster (text) VALUES ('((0,0),2)'::circle);
1386 INSERT INTO caster (circle) VALUES ('((0,0),2)'::citext);
1387 ERROR: column "circle" is of type circle but expression is of type citext
1388 LINE 1: INSERT INTO caster (circle) VALUES ('((0,0),2)'::cite...
1390 HINT: You will need to rewrite or cast the expression.
1391 INSERT INTO caster (citext) VALUES ('((0,0),2)'::circle);
1392 -- Cannot cast to bit on assignment.
1393 INSERT INTO caster (bit) VALUES ('101'::text);
1394 ERROR: column "bit" is of type bit but expression is of type text
1395 LINE 1: INSERT INTO caster (bit) VALUES ('101'::text);
1397 HINT: You will need to rewrite or cast the expression.
1398 INSERT INTO caster (text) VALUES ('101'::bit);
1399 INSERT INTO caster (bit) VALUES ('101'::citext);
1400 ERROR: column "bit" is of type bit but expression is of type citext
1401 LINE 1: INSERT INTO caster (bit) VALUES ('101'::citext);
1403 HINT: You will need to rewrite or cast the expression.
1404 INSERT INTO caster (citext) VALUES ('101'::bit);
1405 -- Cannot cast to bit varying on assignment.
1406 INSERT INTO caster (bitv) VALUES ('101'::text);
1407 ERROR: column "bitv" is of type bit varying but expression is of type text
1408 LINE 1: INSERT INTO caster (bitv) VALUES ('101'::text);
1410 HINT: You will need to rewrite or cast the expression.
1411 INSERT INTO caster (text) VALUES ('101'::bit varying);
1412 INSERT INTO caster (bitv) VALUES ('101'::citext);
1413 ERROR: column "bitv" is of type bit varying but expression is of type citext
1414 LINE 1: INSERT INTO caster (bitv) VALUES ('101'::citext);
1416 HINT: You will need to rewrite or cast the expression.
1417 INSERT INTO caster (citext) VALUES ('101'::bit varying);
1418 -- Cannot cast to tsvector on assignment.
1419 INSERT INTO caster (tsvector) VALUES ('the fat cat'::text);
1420 ERROR: column "tsvector" is of type tsvector but expression is of type text
1421 LINE 1: INSERT INTO caster (tsvector) VALUES ('the fat cat'::te...
1423 HINT: You will need to rewrite or cast the expression.
1424 INSERT INTO caster (text) VALUES ('the fat cat'::tsvector);
1425 INSERT INTO caster (tsvector) VALUES ('the fat cat'::citext);
1426 ERROR: column "tsvector" is of type tsvector but expression is of type citext
1427 LINE 1: INSERT INTO caster (tsvector) VALUES ('the fat cat'::ci...
1429 HINT: You will need to rewrite or cast the expression.
1430 INSERT INTO caster (citext) VALUES ('the fat cat'::tsvector);
1431 -- Cannot cast to tsquery on assignment.
1432 INSERT INTO caster (tsquery) VALUES ('fat & rat'::text);
1433 ERROR: column "tsquery" is of type tsquery but expression is of type text
1434 LINE 1: INSERT INTO caster (tsquery) VALUES ('fat & rat'::text...
1436 HINT: You will need to rewrite or cast the expression.
1437 INSERT INTO caster (text) VALUES ('fat & rat'::tsquery);
1438 INSERT INTO caster (tsquery) VALUES ('fat & rat'::citext);
1439 ERROR: column "tsquery" is of type tsquery but expression is of type citext
1440 LINE 1: INSERT INTO caster (tsquery) VALUES ('fat & rat'::cite...
1442 HINT: You will need to rewrite or cast the expression.
1443 INSERT INTO caster (citext) VALUES ('fat & rat'::tsquery);
1444 -- Cannot cast to uuid on assignment.
1445 INSERT INTO caster (uuid) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::text);
1446 ERROR: column "uuid" is of type uuid but expression is of type text
1447 LINE 1: INSERT INTO caster (uuid) VALUES ('a0eebc99-9c0b-4e...
1449 HINT: You will need to rewrite or cast the expression.
1450 INSERT INTO caster (text) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid);
1451 INSERT INTO caster (uuid) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::citext);
1452 ERROR: column "uuid" is of type uuid but expression is of type citext
1453 LINE 1: INSERT INTO caster (uuid) VALUES ('a0eebc99-9c0b-4e...
1455 HINT: You will need to rewrite or cast the expression.
1456 INSERT INTO caster (citext) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid);
1457 -- Table 9-5. SQL String Functions and Operators
1458 SELECT 'D'::citext || 'avid'::citext = 'David'::citext AS citext_concat;
1464 SELECT 'Value: '::citext || 42 = 'Value: 42' AS text_concat;
1470 SELECT 42 || ': value'::citext ='42: value' AS int_concat;
1476 SELECT bit_length('jose'::citext) = 32 AS t;
1482 SELECT bit_length( name ) = bit_length( name::text ) AS t FROM srt;
1491 SELECT textlen( name ) = textlen( name::text ) AS t FROM srt;
1500 SELECT char_length( name ) = char_length( name::text ) AS t FROM srt;
1509 SELECT lower( name ) = lower( name::text ) AS t FROM srt;
1518 SELECT octet_length( name ) = octet_length( name::text ) AS t FROM srt;
1527 SELECT overlay( name placing 'hom' from 2 for 4) = overlay( name::text placing 'hom' from 2 for 4) AS t FROM srt;
1536 SELECT position( 'a' IN name ) = position( 'a' IN name::text ) AS t FROM srt;
1545 SELECT substr('alphabet'::citext, 3) = 'phabet' AS t;
1551 SELECT substr('alphabet'::citext, 3, 2) = 'ph' AS t;
1557 SELECT substring('alphabet'::citext, 3) = 'phabet' AS t;
1563 SELECT substring('alphabet'::citext, 3, 2) = 'ph' AS t;
1569 SELECT substring('Thomas'::citext from 2 for 3) = 'hom' AS t;
1575 SELECT substring('Thomas'::citext from 2) = 'homas' AS t;
1581 SELECT substring('Thomas'::citext from '...$') = 'mas' AS t;
1587 SELECT substring('Thomas'::citext similar '%#"o_a#"_' escape '#') = 'oma' AS t;
1593 SELECT trim(' trim '::citext) = 'trim' AS t;
1599 SELECT trim('xxxxxtrimxxxx'::citext, 'x'::citext) = 'trim' AS t;
1605 SELECT trim('xxxxxxtrimxxxx'::text, 'x'::citext) = 'trim' AS t;
1611 SELECT trim('xxxxxtrimxxxx'::text, 'x'::citext) = 'trim' AS t;
1617 SELECT upper( name ) = upper( name::text ) AS t FROM srt;
1626 -- Table 9-6. Other String Functions.
1627 SELECT ascii( name ) = ascii( name::text ) AS t FROM srt;
1636 SELECT btrim(' trim'::citext ) = 'trim' AS t;
1642 SELECT btrim('xxxxxtrimxxxx'::citext, 'x'::citext ) = 'trim' AS t;
1648 SELECT btrim('xyxtrimyyx'::citext, 'xy'::citext) = 'trim' AS t;
1654 SELECT btrim('xyxtrimyyx'::text, 'xy'::citext) = 'trim' AS t;
1660 SELECT btrim('xyxtrimyyx'::citext, 'xy'::text ) = 'trim' AS t;
1666 -- chr() takes an int and returns text.
1667 -- convert() and convert_from take bytea and return text.
1668 SELECT convert_from( name::bytea, 'SQL_ASCII' ) = convert_from( name::text::bytea, 'SQL_ASCII' ) AS t FROM srt;
1677 SELECT decode('MTIzAAE='::citext, 'base64') = decode('MTIzAAE='::text, 'base64') AS t;
1683 -- encode() takes bytea and returns text.
1684 SELECT initcap('hi THOMAS'::citext) = initcap('hi THOMAS'::text) AS t;
1690 SELECT length( name ) = length( name::text ) AS t FROM srt;
1699 SELECT lpad('hi'::citext, 5 ) = ' hi' AS t;
1705 SELECT lpad('hi'::citext, 5, 'xy'::citext) = 'xyxhi' AS t;
1711 SELECT lpad('hi'::text, 5, 'xy'::citext) = 'xyxhi' AS t;
1717 SELECT lpad('hi'::citext, 5, 'xy'::text ) = 'xyxhi' AS t;
1723 SELECT ltrim(' trim'::citext ) = 'trim' AS t;
1729 SELECT ltrim('zzzytrim'::citext, 'xyz'::citext) = 'trim' AS t;
1735 SELECT ltrim('zzzytrim'::text, 'xyz'::citext) = 'trim' AS t;
1741 SELECT ltrim('zzzytrim'::citext, 'xyz'::text ) = 'trim' AS t;
1747 -- pg_client_encoding() takes no args and returns name.
1748 SELECT quote_ident( name ) = quote_ident( name::text ) AS t FROM srt;
1757 SELECT quote_literal( name ) = quote_literal( name::text ) AS t FROM srt;
1766 SELECT regexp_match('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
1772 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
1778 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1784 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1790 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
1796 SELECT regexp_match('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1802 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1808 -- c forces case-sensitive
1809 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no result";
1816 SELECT regexp_match('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g') AS "error";
1817 ERROR: regexp_match() does not support the "global" option
1818 HINT: Use the regexp_matches function instead.
1819 CONTEXT: SQL function "regexp_match" statement 1
1820 SELECT regexp_matches('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
1826 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
1832 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1838 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1844 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
1850 SELECT regexp_matches('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1856 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1862 -- c forces case-sensitive
1863 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no rows";
1868 -- g allows multiple output rows
1869 SELECT regexp_matches('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g'::citext) AS "two rows";
1876 SELECT regexp_replace('Thomas'::citext, '.[mN]a.', 'M') = 'ThM' AS t;
1882 SELECT regexp_replace('Thomas'::citext, '.[MN]A.', 'M') = 'ThM' AS t;
1888 SELECT regexp_replace('Thomas', '.[MN]A.'::citext, 'M') = 'ThM' AS t;
1894 SELECT regexp_replace('Thomas'::citext, '.[MN]A.'::citext, 'M') = 'ThM' AS t;
1900 -- c forces case-sensitive
1901 SELECT regexp_replace('Thomas'::citext, '.[MN]A.'::citext, 'M', 'c') = 'Thomas' AS t;
1907 SELECT regexp_split_to_array('hello world'::citext, E'\\s+') = ARRAY[ 'hello', 'world' ] AS t;
1913 SELECT regexp_split_to_array('helloTworld'::citext, 't') = ARRAY[ 'hello', 'world' ] AS t;
1919 SELECT regexp_split_to_array('helloTworld', 't'::citext) = ARRAY[ 'hello', 'world' ] AS t;
1925 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext) = ARRAY[ 'hello', 'world' ] AS t;
1931 SELECT regexp_split_to_array('helloTworld'::citext, 't', 's') = ARRAY[ 'hello', 'world' ] AS t;
1937 SELECT regexp_split_to_array('helloTworld', 't'::citext, 's') = ARRAY[ 'hello', 'world' ] AS t;
1943 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext, 's') = ARRAY[ 'hello', 'world' ] AS t;
1949 -- c forces case-sensitive
1950 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext, 'c') = ARRAY[ 'helloTworld' ] AS t;
1956 SELECT regexp_split_to_table('hello world'::citext, E'\\s+') AS words;
1963 SELECT regexp_split_to_table('helloTworld'::citext, 't') AS words;
1970 SELECT regexp_split_to_table('helloTworld', 't'::citext) AS words;
1977 SELECT regexp_split_to_table('helloTworld'::citext, 't'::citext) AS words;
1984 -- c forces case-sensitive
1985 SELECT regexp_split_to_table('helloTworld'::citext, 't'::citext, 'c') AS word;
1991 SELECT repeat('Pg'::citext, 4) = 'PgPgPgPg' AS t;
1997 SELECT replace('abcdefabcdef'::citext, 'cd', 'XX') = 'abXXefabXXef' AS t;
2003 SELECT replace('abcdefabcdef'::citext, 'CD', 'XX') = 'abXXefabXXef' AS t;
2009 SELECT replace('ab^is$abcdef'::citext, '^is$', 'XX') = 'abXXabcdef' AS t;
2015 SELECT replace('abcdefabcdef', 'cd'::citext, 'XX') = 'abXXefabXXef' AS t;
2021 SELECT replace('abcdefabcdef', 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
2027 SELECT replace('ab^is$abcdef', '^is$'::citext, 'XX') = 'abXXabcdef' AS t;
2033 SELECT replace('abcdefabcdef'::citext, 'cd'::citext, 'XX') = 'abXXefabXXef' AS t;
2039 SELECT replace('abcdefabcdef'::citext, 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
2045 SELECT replace('ab^is$abcdef'::citext, '^is$'::citext, 'XX') = 'abXXabcdef' AS t;
2051 SELECT rpad('hi'::citext, 5 ) = 'hi ' AS t;
2057 SELECT rpad('hi'::citext, 5, 'xy'::citext) = 'hixyx' AS t;
2063 SELECT rpad('hi'::text, 5, 'xy'::citext) = 'hixyx' AS t;
2069 SELECT rpad('hi'::citext, 5, 'xy'::text ) = 'hixyx' AS t;
2075 SELECT rtrim('trim '::citext ) = 'trim' AS t;
2081 SELECT rtrim('trimxxxx'::citext, 'x'::citext) = 'trim' AS t;
2087 SELECT rtrim('trimxxxx'::text, 'x'::citext) = 'trim' AS t;
2093 SELECT rtrim('trimxxxx'::text, 'x'::text ) = 'trim' AS t;
2099 SELECT split_part('abc~@~def~@~ghi'::citext, '~@~', 2) = 'def' AS t;
2105 SELECT split_part('abcTdefTghi'::citext, 't', 2) = 'def' AS t;
2111 SELECT split_part('abcTdefTghi'::citext, 't'::citext, 2) = 'def' AS t;
2117 SELECT split_part('abcTdefTghi', 't'::citext, 2) = 'def' AS t;
2123 SELECT strpos('high'::citext, 'gh' ) = 3 AS t;
2129 SELECT strpos('high', 'gh'::citext) = 3 AS t;
2135 SELECT strpos('high'::citext, 'gh'::citext) = 3 AS t;
2141 SELECT strpos('high'::citext, 'GH' ) = 3 AS t;
2147 SELECT strpos('high', 'GH'::citext) = 3 AS t;
2153 SELECT strpos('high'::citext, 'GH'::citext) = 3 AS t;
2159 -- to_ascii() does not support UTF-8.
2160 -- to_hex() takes a numeric argument.
2161 SELECT substr('alphabet', 3, 2) = 'ph' AS t;
2167 SELECT translate('abcdefabcdef'::citext, 'cd', 'XX') = 'abXXefabXXef' AS t;
2173 SELECT translate('abcdefabcdef'::citext, 'CD', 'XX') = 'abXXefabXXef' AS t;
2179 SELECT translate('abcdefabcdef'::citext, 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
2185 SELECT translate('abcdefabcdef', 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
2191 -- Table 9-20. Formatting Functions
2192 SELECT to_date('05 Dec 2000'::citext, 'DD Mon YYYY'::citext)
2193 = to_date('05 Dec 2000', 'DD Mon YYYY') AS t;
2199 SELECT to_date('05 Dec 2000'::citext, 'DD Mon YYYY')
2200 = to_date('05 Dec 2000', 'DD Mon YYYY') AS t;
2206 SELECT to_date('05 Dec 2000', 'DD Mon YYYY'::citext)
2207 = to_date('05 Dec 2000', 'DD Mon YYYY') AS t;
2213 SELECT to_number('12,454.8-'::citext, '99G999D9S'::citext)
2214 = to_number('12,454.8-', '99G999D9S') AS t;
2220 SELECT to_number('12,454.8-'::citext, '99G999D9S')
2221 = to_number('12,454.8-', '99G999D9S') AS t;
2227 SELECT to_number('12,454.8-', '99G999D9S'::citext)
2228 = to_number('12,454.8-', '99G999D9S') AS t;
2234 SELECT to_timestamp('05 Dec 2000'::citext, 'DD Mon YYYY'::citext)
2235 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
2241 SELECT to_timestamp('05 Dec 2000'::citext, 'DD Mon YYYY')
2242 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
2248 SELECT to_timestamp('05 Dec 2000', 'DD Mon YYYY'::citext)
2249 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
2255 -- Try assigning function results to a column.
2256 SELECT COUNT(*) = 8::bigint AS t FROM try;
2263 VALUES ( to_char( now()::timestamp, 'HH12:MI:SS') ),
2264 ( to_char( now() + '1 sec'::interval, 'HH12:MI:SS') ), -- timestamptz
2265 ( to_char( '15h 2m 12s'::interval, 'HH24:MI:SS') ),
2266 ( to_char( current_date, '999') ),
2267 ( to_char( 125::int, '999') ),
2268 ( to_char( 127::int4, '999') ),
2269 ( to_char( 126::int8, '999') ),
2270 ( to_char( 128.8::real, '999D9') ),
2271 ( to_char( 125.7::float4, '999D9') ),
2272 ( to_char( 125.9::float8, '999D9') ),
2273 ( to_char( -125.8::numeric, '999D99S') );
2274 SELECT COUNT(*) = 19::bigint AS t FROM try;
2280 SELECT like_escape( name, '' ) = like_escape( name::text, '' ) AS t FROM srt;
2289 SELECT like_escape( name::text, ''::citext ) = like_escape( name::text, '' ) AS t FROM srt;
2298 -- Ensure correct behavior for citext with materialized views.
2299 CREATE TABLE citext_table (
2300 id serial primary key,
2303 INSERT INTO citext_table (name)
2304 VALUES ('one'), ('two'), ('three'), (NULL), (NULL);
2305 CREATE MATERIALIZED VIEW citext_matview AS
2306 SELECT * FROM citext_table;
2307 CREATE UNIQUE INDEX citext_matview_id
2308 ON citext_matview (id);
2310 FROM citext_matview m
2311 FULL JOIN citext_table t ON (t.id = m.id AND t *= m)
2312 WHERE t.id IS NULL OR m.id IS NULL;
2313 id | name | id | name
2314 ----+------+----+------
2317 UPDATE citext_table SET name = 'Two' WHERE name = 'TWO';
2319 FROM citext_matview m
2320 FULL JOIN citext_table t ON (t.id = m.id AND t *= m)
2321 WHERE t.id IS NULL OR m.id IS NULL;
2322 id | name | id | name
2323 ----+------+----+------
2328 REFRESH MATERIALIZED VIEW CONCURRENTLY citext_matview;
2329 SELECT * FROM citext_matview ORDER BY id;
2339 -- test citext_pattern_cmp() function explicitly.
2340 SELECT citext_pattern_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
2346 SELECT citext_pattern_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
2352 SELECT citext_pattern_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
2358 SELECT citext_pattern_cmp('B'::citext, 'a'::citext) > 0 AS true;
2364 SELECT citext_pattern_cmp('a'::citext, 'B'::citext) < 0 AS true;
2370 SELECT citext_pattern_cmp('A'::citext, 'b'::citext) < 0 AS true;
2376 SELECT citext_pattern_cmp('ABCD'::citext, 'abc'::citext) > 0 AS true;
2382 SELECT citext_pattern_cmp('ABC'::citext, 'abcd'::citext) < 0 AS true;
2388 -- test operator functions
2390 SELECT citext_pattern_lt('a'::citext, 'b'::citext) AS true;
2396 SELECT citext_pattern_lt('A'::citext, 'b'::citext) AS true;
2402 SELECT citext_pattern_lt('a'::citext, 'B'::citext) AS true;
2408 SELECT citext_pattern_lt('b'::citext, 'a'::citext) AS false;
2414 SELECT citext_pattern_lt('B'::citext, 'a'::citext) AS false;
2420 SELECT citext_pattern_lt('b'::citext, 'A'::citext) AS false;
2427 SELECT citext_pattern_le('a'::citext, 'a'::citext) AS true;
2433 SELECT citext_pattern_le('a'::citext, 'A'::citext) AS true;
2439 SELECT citext_pattern_le('A'::citext, 'a'::citext) AS true;
2445 SELECT citext_pattern_le('A'::citext, 'A'::citext) AS true;
2451 SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
2457 SELECT citext_pattern_le('A'::citext, 'b'::citext) AS true;
2463 SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
2469 SELECT citext_pattern_le('b'::citext, 'a'::citext) AS false;
2475 SELECT citext_pattern_le('B'::citext, 'a'::citext) AS false;
2481 SELECT citext_pattern_le('b'::citext, 'A'::citext) AS false;
2488 SELECT citext_pattern_gt('a'::citext, 'b'::citext) AS false;
2494 SELECT citext_pattern_gt('A'::citext, 'b'::citext) AS false;
2500 SELECT citext_pattern_gt('a'::citext, 'B'::citext) AS false;
2506 SELECT citext_pattern_gt('b'::citext, 'a'::citext) AS true;
2512 SELECT citext_pattern_gt('B'::citext, 'a'::citext) AS true;
2518 SELECT citext_pattern_gt('b'::citext, 'A'::citext) AS true;
2525 SELECT citext_pattern_ge('a'::citext, 'a'::citext) AS true;
2531 SELECT citext_pattern_ge('a'::citext, 'A'::citext) AS true;
2537 SELECT citext_pattern_ge('A'::citext, 'a'::citext) AS true;
2543 SELECT citext_pattern_ge('A'::citext, 'A'::citext) AS true;
2549 SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
2555 SELECT citext_pattern_ge('A'::citext, 'b'::citext) AS false;
2561 SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
2567 SELECT citext_pattern_ge('b'::citext, 'a'::citext) AS true;
2573 SELECT citext_pattern_ge('B'::citext, 'a'::citext) AS true;
2579 SELECT citext_pattern_ge('b'::citext, 'A'::citext) AS true;
2585 -- Test ~<~ and ~<=~
2586 SELECT 'a'::citext ~<~ 'B'::citext AS t;
2592 SELECT 'b'::citext ~<~ 'A'::citext AS f;
2598 SELECT 'a'::citext ~<=~ 'B'::citext AS t;
2604 SELECT 'a'::citext ~<=~ 'A'::citext AS t;
2610 -- Test ~>~ and ~>=~
2611 SELECT 'B'::citext ~>~ 'a'::citext AS t;
2617 SELECT 'b'::citext ~>~ 'A'::citext AS t;
2623 SELECT 'B'::citext ~>~ 'b'::citext AS f;
2629 SELECT 'B'::citext ~>=~ 'b'::citext AS t;
2635 -- Test implicit casting. citext casts to text, but not vice-versa.
2636 SELECT 'B'::citext ~<~ 'a'::text AS t; -- text wins.
2642 SELECT 'B'::citext ~<=~ 'a'::text AS t; -- text wins.
2648 SELECT 'a'::citext ~>~ 'B'::text AS t; -- text wins.
2654 SELECT 'a'::citext ~>=~ 'B'::text AS t; -- text wins.
2660 -- Test implicit casting. citext casts to varchar, but not vice-versa.
2661 SELECT 'B'::citext ~<~ 'a'::varchar AS t; -- varchar wins.
2667 SELECT 'B'::citext ~<=~ 'a'::varchar AS t; -- varchar wins.
2673 SELECT 'a'::citext ~>~ 'B'::varchar AS t; -- varchar wins.
2679 SELECT 'a'::citext ~>=~ 'B'::varchar AS t; -- varchar wins.