Debian Codegraph @

contrib/citext/sql/citext.sql

raw
1 --
2 -- Test citext datatype
3 --
4
5 CREATE EXTENSION citext;
6
7 -- Check whether any of our opclasses fail amvalidate
8 SELECT amname, opcname
9 FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
10 WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
11
12 -- Test the operators and indexing functions
13
14 -- Test = and <>.
15 SELECT 'a'::citext = 'a'::citext AS t;
16 SELECT 'a'::citext = 'A'::citext AS t;
17 SELECT 'a'::citext = 'A'::text AS f; -- text wins the discussion
18 SELECT 'a'::citext = 'b'::citext AS f;
19 SELECT 'a'::citext = 'ab'::citext AS f;
20 SELECT 'a'::citext <> 'ab'::citext AS t;
21
22 -- Test > and >=
23 SELECT 'B'::citext > 'a'::citext AS t;
24 SELECT 'b'::citext > 'A'::citext AS t;
25 SELECT 'B'::citext > 'b'::citext AS f;
26 SELECT 'B'::citext >= 'b'::citext AS t;
27
28 -- Test < and <=
29 SELECT 'a'::citext < 'B'::citext AS t;
30 SELECT 'a'::citext <= 'B'::citext AS t;
31
32 -- Test implicit casting. citext casts to text, but not vice-versa.
33 SELECT 'a'::citext = 'a'::text AS t;
34 SELECT 'A'::text <> 'a'::citext AS t;
35
36 SELECT 'B'::citext < 'a'::text AS t; -- text wins.
37 SELECT 'B'::citext <= 'a'::text AS t; -- text wins.
38
39 SELECT 'a'::citext > 'B'::text AS t; -- text wins.
40 SELECT 'a'::citext >= 'B'::text AS t; -- text wins.
41
42 -- Test implicit casting. citext casts to varchar, but not vice-versa.
43 SELECT 'a'::citext = 'a'::varchar AS t;
44 SELECT 'A'::varchar <> 'a'::citext AS t;
45
46 SELECT 'B'::citext < 'a'::varchar AS t; -- varchar wins.
47 SELECT 'B'::citext <= 'a'::varchar AS t; -- varchar wins.
48
49 SELECT 'a'::citext > 'B'::varchar AS t; -- varchar wins.
50 SELECT 'a'::citext >= 'B'::varchar AS t; -- varchar wins.
51
52 -- A couple of longer examples to ensure that we don't get any issues with bad
53 -- conversions to char[] in the c code. Yes, I did do this.
54
55 SELECT 'aardvark'::citext = 'aardvark'::citext AS t;
56 SELECT 'aardvark'::citext = 'aardVark'::citext AS t;
57
58 -- Check the citext_cmp() function explicitly.
59 SELECT citext_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
60 SELECT citext_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
61 SELECT citext_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
62 SELECT citext_cmp('B'::citext, 'a'::citext) > 0 AS true;
63
64 -- Check the citext_hash() and citext_hash_extended() function explicitly.
65 SELECT v as value, citext_hash(v)::bit(32) as standard,
66 citext_hash_extended(v, 0)::bit(32) as extended0,
67 citext_hash_extended(v, 1)::bit(32) as extended1
68 FROM (VALUES (NULL::citext), ('PostgreSQL'), ('eIpUEtqmY89'), ('AXKEJBTK'),
69 ('muop28x03'), ('yi3nm0d73')) x(v)
70 WHERE citext_hash(v)::bit(32) != citext_hash_extended(v, 0)::bit(32)
71 OR citext_hash(v)::bit(32) = citext_hash_extended(v, 1)::bit(32);
72
73 -- Do some tests using a table and index.
74
75 CREATE TEMP TABLE try (
76 name citext PRIMARY KEY
77 );
78
79 INSERT INTO try (name)
80 VALUES ('a'), ('ab'), ('â'), ('aba'), ('b'), ('ba'), ('bab'), ('AZ');
81
82 SELECT name, 'a' = name AS eq_a FROM try WHERE name <> 'â';
83 SELECT name, 'a' = name AS t FROM try where name = 'a';
84 SELECT name, 'A' = name AS "eq_A" FROM try WHERE name <> 'â';
85 SELECT name, 'A' = name AS t FROM try where name = 'A';
86 SELECT name, 'A' = name AS t FROM try where name = 'A';
87
88 -- expected failures on duplicate key
89 INSERT INTO try (name) VALUES ('a');
90 INSERT INTO try (name) VALUES ('A');
91 INSERT INTO try (name) VALUES ('aB');
92
93 -- Make sure that citext_smaller() and citext_larger() work properly.
94 SELECT citext_smaller( 'ab'::citext, 'ac'::citext ) = 'ab' AS t;
95 SELECT citext_smaller( 'ABC'::citext, 'bbbb'::citext ) = 'ABC' AS t;
96 SELECT citext_smaller( 'aardvark'::citext, 'Aaba'::citext ) = 'Aaba' AS t;
97 SELECT citext_smaller( 'aardvark'::citext, 'AARDVARK'::citext ) = 'AARDVARK' AS t;
98
99 SELECT citext_larger( 'ab'::citext, 'ac'::citext ) = 'ac' AS t;
100 SELECT citext_larger( 'ABC'::citext, 'bbbb'::citext ) = 'bbbb' AS t;
101 SELECT citext_larger( 'aardvark'::citext, 'Aaba'::citext ) = 'aardvark' AS t;
102
103 -- Test aggregate functions and sort ordering
104
105 CREATE TEMP TABLE srt (
106 name CITEXT
107 );
108
109 INSERT INTO srt (name)
110 VALUES ('abb'),
111 ('ABA'),
112 ('ABC'),
113 ('abd');
114
115 CREATE INDEX srt_name ON srt (name);
116
117 -- Check the min() and max() aggregates, with and without index.
118 set enable_seqscan = off;
119 SELECT MIN(name) AS "ABA" FROM srt;
120 SELECT MAX(name) AS abd FROM srt;
121 reset enable_seqscan;
122 set enable_indexscan = off;
123 SELECT MIN(name) AS "ABA" FROM srt;
124 SELECT MAX(name) AS abd FROM srt;
125 reset enable_indexscan;
126
127 -- Check sorting likewise
128 set enable_seqscan = off;
129 SELECT name FROM srt ORDER BY name;
130 reset enable_seqscan;
131 set enable_indexscan = off;
132 SELECT name FROM srt ORDER BY name;
133 reset enable_indexscan;
134
135 -- Test assignment casts.
136 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::text;
137 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::varchar;
138 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::bpchar;
139 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA';
140 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::citext;
141
142 -- LIKE should be case-insensitive
143 SELECT name FROM srt WHERE name LIKE '%a%' ORDER BY name;
144 SELECT name FROM srt WHERE name NOT LIKE '%b%' ORDER BY name;
145 SELECT name FROM srt WHERE name LIKE '%A%' ORDER BY name;
146 SELECT name FROM srt WHERE name NOT LIKE '%B%' ORDER BY name;
147
148 -- ~~ should be case-insensitive
149 SELECT name FROM srt WHERE name ~~ '%a%' ORDER BY name;
150 SELECT name FROM srt WHERE name !~~ '%b%' ORDER BY name;
151 SELECT name FROM srt WHERE name ~~ '%A%' ORDER BY name;
152 SELECT name FROM srt WHERE name !~~ '%B%' ORDER BY name;
153
154 -- ~ should be case-insensitive
155 SELECT name FROM srt WHERE name ~ '^a' ORDER BY name;
156 SELECT name FROM srt WHERE name !~ 'a$' ORDER BY name;
157 SELECT name FROM srt WHERE name ~ '^A' ORDER BY name;
158 SELECT name FROM srt WHERE name !~ 'A$' ORDER BY name;
159
160 -- SIMILAR TO should be case-insensitive.
161 SELECT name FROM srt WHERE name SIMILAR TO '%a.*';
162 SELECT name FROM srt WHERE name SIMILAR TO '%A.*';
163
164 -- Explicit casts.
165 SELECT true::citext = 'true' AS t;
166 SELECT 'true'::citext::boolean = true AS t;
167
168 SELECT 4::citext = '4' AS t;
169 SELECT 4::int4::citext = '4' AS t;
170 SELECT '4'::citext::int4 = 4 AS t;
171 SELECT 4::integer::citext = '4' AS t;
172 SELECT '4'::citext::integer = 4 AS t;
173
174 SELECT 4::int8::citext = '4' AS t;
175 SELECT '4'::citext::int8 = 4 AS t;
176 SELECT 4::bigint::citext = '4' AS t;
177 SELECT '4'::citext::bigint = 4 AS t;
178
179 SELECT 4::int2::citext = '4' AS t;
180 SELECT '4'::citext::int2 = 4 AS t;
181 SELECT 4::smallint::citext = '4' AS t;
182 SELECT '4'::citext::smallint = 4 AS t;
183
184 SELECT 4.0::numeric = '4.0' AS t;
185 SELECT '4.0'::citext::numeric = 4.0 AS t;
186 SELECT 4.0::decimal = '4.0' AS t;
187 SELECT '4.0'::citext::decimal = 4.0 AS t;
188
189 SELECT 4.0::real = '4.0' AS t;
190 SELECT '4.0'::citext::real = 4.0 AS t;
191 SELECT 4.0::float4 = '4.0' AS t;
192 SELECT '4.0'::citext::float4 = 4.0 AS t;
193
194 SELECT 4.0::double precision = '4.0' AS t;
195 SELECT '4.0'::citext::double precision = 4.0 AS t;
196 SELECT 4.0::float8 = '4.0' AS t;
197 SELECT '4.0'::citext::float8 = 4.0 AS t;
198
199 SELECT 'foo'::name::citext = 'foo' AS t;
200 SELECT 'foo'::citext::name = 'foo'::name AS t;
201
202 SELECT 'f'::char::citext = 'f' AS t;
203 SELECT 'f'::citext::char = 'f'::char AS t;
204
205 SELECT 'f'::"char"::citext = 'f' AS t;
206 SELECT 'f'::citext::"char" = 'f'::"char" AS t;
207
208 SELECT '100'::money::citext = '$100.00' AS t;
209 SELECT '100'::citext::money = '100'::money AS t;
210
211 SELECT 'a'::char::citext = 'a' AS t;
212 SELECT 'a'::citext::char = 'a'::char AS t;
213
214 SELECT 'foo'::varchar::citext = 'foo' AS t;
215 SELECT 'foo'::citext::varchar = 'foo'::varchar AS t;
216
217 SELECT 'foo'::text::citext = 'foo' AS t;
218 SELECT 'foo'::citext::text = 'foo'::text AS t;
219
220 SELECT '192.168.100.128/25'::cidr::citext = '192.168.100.128/25' AS t;
221 SELECT '192.168.100.128/25'::citext::cidr = '192.168.100.128/25'::cidr AS t;
222
223 SELECT '192.168.100.128'::inet::citext = '192.168.100.128/32' AS t;
224 SELECT '192.168.100.128'::citext::inet = '192.168.100.128'::inet AS t;
225
226 SELECT '08:00:2b:01:02:03'::macaddr::citext = '08:00:2b:01:02:03' AS t;
227 SELECT '08:00:2b:01:02:03'::citext::macaddr = '08:00:2b:01:02:03'::macaddr AS t;
228
229 SELECT '1999-01-08 04:05:06'::timestamp::citext = '1999-01-08 04:05:06'::timestamp::text AS t;
230 SELECT '1999-01-08 04:05:06'::citext::timestamp = '1999-01-08 04:05:06'::timestamp AS t;
231 SELECT '1999-01-08 04:05:06'::timestamptz::citext = '1999-01-08 04:05:06'::timestamptz::text AS t;
232 SELECT '1999-01-08 04:05:06'::citext::timestamptz = '1999-01-08 04:05:06'::timestamptz AS t;
233
234 SELECT '1 hour'::interval::citext = '1 hour'::interval::text AS t;
235 SELECT '1 hour'::citext::interval = '1 hour'::interval AS t;
236
237 SELECT '1999-01-08'::date::citext = '1999-01-08'::date::text AS t;
238 SELECT '1999-01-08'::citext::date = '1999-01-08'::date AS t;
239
240 SELECT '04:05:06'::time::citext = '04:05:06' AS t;
241 SELECT '04:05:06'::citext::time = '04:05:06'::time AS t;
242 SELECT '04:05:06'::timetz::citext = '04:05:06'::timetz::text AS t;
243 SELECT '04:05:06'::citext::timetz = '04:05:06'::timetz AS t;
244
245 SELECT '( 1 , 1)'::point::citext = '(1,1)' AS t;
246 SELECT '( 1 , 1)'::citext::point ~= '(1,1)'::point AS t;
247 SELECT '( 1 , 1 ) , ( 2 , 2 )'::lseg::citext = '[(1,1),(2,2)]' AS t;
248 SELECT '( 1 , 1 ) , ( 2 , 2 )'::citext::lseg = '[(1,1),(2,2)]'::lseg AS t;
249 SELECT '( 0 , 0 ) , ( 1 , 1 )'::box::citext = '(0,0),(1,1)'::box::text AS t;
250 SELECT '( 0 , 0 ) , ( 1 , 1 )'::citext::box ~= '(0,0),(1,1)'::text::box AS t;
251
252 SELECT '((0,0),(1,1),(2,0))'::path::citext = '((0,0),(1,1),(2,0))' AS t;
253 SELECT '((0,0),(1,1),(2,0))'::citext::path = '((0,0),(1,1),(2,0))'::path AS t;
254
255 SELECT '((0,0),(1,1))'::polygon::citext = '((0,0),(1,1))' AS t;
256 SELECT '((0,0),(1,1))'::citext::polygon ~= '((0,0),(1,1))'::polygon AS t;
257
258 SELECT '((0,0),2)'::circle::citext = '((0,0),2)'::circle::text AS t;
259 SELECT '((0,0),2)'::citext::circle ~= '((0,0),2)'::text::circle AS t;
260
261 SELECT '101'::bit::citext = '101'::bit::text AS t;
262 SELECT '101'::citext::bit = '101'::text::bit AS t;
263 SELECT '101'::bit varying::citext = '101'::bit varying::text AS t;
264 SELECT '101'::citext::bit varying = '101'::text::bit varying AS t;
265 SELECT 'a fat cat'::tsvector::citext = '''a'' ''cat'' ''fat''' AS t;
266 SELECT 'a fat cat'::citext::tsvector = 'a fat cat'::tsvector AS t;
267 SELECT 'fat & rat'::tsquery::citext = '''fat'' & ''rat''' AS t;
268 SELECT 'fat & rat'::citext::tsquery = 'fat & rat'::tsquery AS t;
269 SELECT 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid::citext = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' AS t;
270 SELECT 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::citext::uuid = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid AS t;
271
272 CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
273 SELECT 'sad'::mood::citext = 'sad' AS t;
274 SELECT 'sad'::citext::mood = 'sad'::mood AS t;
275
276 -- Assignment casts.
277 CREATE TABLE caster (
278 citext citext,
279 text text,
280 varchar varchar,
281 bpchar bpchar,
282 char char,
283 chr "char",
284 name name,
285 bytea bytea,
286 boolean boolean,
287 float4 float4,
288 float8 float8,
289 numeric numeric,
290 int8 int8,
291 int4 int4,
292 int2 int2,
293 cidr cidr,
294 inet inet,
295 macaddr macaddr,
296 money money,
297 timestamp timestamp,
298 timestamptz timestamptz,
299 interval interval,
300 date date,
301 time time,
302 timetz timetz,
303 point point,
304 lseg lseg,
305 box box,
306 path path,
307 polygon polygon,
308 circle circle,
309 bit bit,
310 bitv bit varying,
311 tsvector tsvector,
312 tsquery tsquery,
313 uuid uuid
314 );
315
316 INSERT INTO caster (text) VALUES ('foo'::citext);
317 INSERT INTO caster (citext) VALUES ('foo'::text);
318
319 INSERT INTO caster (varchar) VALUES ('foo'::text);
320 INSERT INTO caster (text) VALUES ('foo'::varchar);
321 INSERT INTO caster (varchar) VALUES ('foo'::citext);
322 INSERT INTO caster (citext) VALUES ('foo'::varchar);
323
324 INSERT INTO caster (bpchar) VALUES ('foo'::text);
325 INSERT INTO caster (text) VALUES ('foo'::bpchar);
326 INSERT INTO caster (bpchar) VALUES ('foo'::citext);
327 INSERT INTO caster (citext) VALUES ('foo'::bpchar);
328
329 INSERT INTO caster (char) VALUES ('f'::text);
330 INSERT INTO caster (text) VALUES ('f'::char);
331 INSERT INTO caster (char) VALUES ('f'::citext);
332 INSERT INTO caster (citext) VALUES ('f'::char);
333
334 INSERT INTO caster (chr) VALUES ('f'::text);
335 INSERT INTO caster (text) VALUES ('f'::"char");
336 INSERT INTO caster (chr) VALUES ('f'::citext); -- requires cast
337 INSERT INTO caster (chr) VALUES ('f'::citext::text);
338 INSERT INTO caster (citext) VALUES ('f'::"char");
339
340 INSERT INTO caster (name) VALUES ('foo'::text);
341 INSERT INTO caster (text) VALUES ('foo'::name);
342 INSERT INTO caster (name) VALUES ('foo'::citext);
343 INSERT INTO caster (citext) VALUES ('foo'::name);
344
345 -- Cannot cast to bytea on assignment.
346 INSERT INTO caster (bytea) VALUES ('foo'::text);
347 INSERT INTO caster (text) VALUES ('foo'::bytea);
348 INSERT INTO caster (bytea) VALUES ('foo'::citext);
349 INSERT INTO caster (citext) VALUES ('foo'::bytea);
350
351 -- Cannot cast to boolean on assignment.
352 INSERT INTO caster (boolean) VALUES ('t'::text);
353 INSERT INTO caster (text) VALUES ('t'::boolean);
354 INSERT INTO caster (boolean) VALUES ('t'::citext);
355 INSERT INTO caster (citext) VALUES ('t'::boolean);
356
357 -- Cannot cast to float8 on assignment.
358 INSERT INTO caster (float8) VALUES ('12.42'::text);
359 INSERT INTO caster (text) VALUES ('12.42'::float8);
360 INSERT INTO caster (float8) VALUES ('12.42'::citext);
361 INSERT INTO caster (citext) VALUES ('12.42'::float8);
362
363 -- Cannot cast to float4 on assignment.
364 INSERT INTO caster (float4) VALUES ('12.42'::text);
365 INSERT INTO caster (text) VALUES ('12.42'::float4);
366 INSERT INTO caster (float4) VALUES ('12.42'::citext);
367 INSERT INTO caster (citext) VALUES ('12.42'::float4);
368
369 -- Cannot cast to numeric on assignment.
370 INSERT INTO caster (numeric) VALUES ('12.42'::text);
371 INSERT INTO caster (text) VALUES ('12.42'::numeric);
372 INSERT INTO caster (numeric) VALUES ('12.42'::citext);
373 INSERT INTO caster (citext) VALUES ('12.42'::numeric);
374
375 -- Cannot cast to int8 on assignment.
376 INSERT INTO caster (int8) VALUES ('12'::text);
377 INSERT INTO caster (text) VALUES ('12'::int8);
378 INSERT INTO caster (int8) VALUES ('12'::citext);
379 INSERT INTO caster (citext) VALUES ('12'::int8);
380
381 -- Cannot cast to int4 on assignment.
382 INSERT INTO caster (int4) VALUES ('12'::text);
383 INSERT INTO caster (text) VALUES ('12'::int4);
384 INSERT INTO caster (int4) VALUES ('12'::citext);
385 INSERT INTO caster (citext) VALUES ('12'::int4);
386
387 -- Cannot cast to int2 on assignment.
388 INSERT INTO caster (int2) VALUES ('12'::text);
389 INSERT INTO caster (text) VALUES ('12'::int2);
390 INSERT INTO caster (int2) VALUES ('12'::citext);
391 INSERT INTO caster (citext) VALUES ('12'::int2);
392
393 -- Cannot cast to cidr on assignment.
394 INSERT INTO caster (cidr) VALUES ('192.168.100.128/25'::text);
395 INSERT INTO caster (text) VALUES ('192.168.100.128/25'::cidr);
396 INSERT INTO caster (cidr) VALUES ('192.168.100.128/25'::citext);
397 INSERT INTO caster (citext) VALUES ('192.168.100.128/25'::cidr);
398
399 -- Cannot cast to inet on assignment.
400 INSERT INTO caster (inet) VALUES ('192.168.100.128'::text);
401 INSERT INTO caster (text) VALUES ('192.168.100.128'::inet);
402 INSERT INTO caster (inet) VALUES ('192.168.100.128'::citext);
403 INSERT INTO caster (citext) VALUES ('192.168.100.128'::inet);
404
405 -- Cannot cast to macaddr on assignment.
406 INSERT INTO caster (macaddr) VALUES ('08:00:2b:01:02:03'::text);
407 INSERT INTO caster (text) VALUES ('08:00:2b:01:02:03'::macaddr);
408 INSERT INTO caster (macaddr) VALUES ('08:00:2b:01:02:03'::citext);
409 INSERT INTO caster (citext) VALUES ('08:00:2b:01:02:03'::macaddr);
410
411 -- Cannot cast to money on assignment.
412 INSERT INTO caster (money) VALUES ('12'::text);
413 INSERT INTO caster (text) VALUES ('12'::money);
414 INSERT INTO caster (money) VALUES ('12'::citext);
415 INSERT INTO caster (citext) VALUES ('12'::money);
416
417 -- Cannot cast to timestamp on assignment.
418 INSERT INTO caster (timestamp) VALUES ('1999-01-08 04:05:06'::text);
419 INSERT INTO caster (text) VALUES ('1999-01-08 04:05:06'::timestamp);
420 INSERT INTO caster (timestamp) VALUES ('1999-01-08 04:05:06'::citext);
421 INSERT INTO caster (citext) VALUES ('1999-01-08 04:05:06'::timestamp);
422
423 -- Cannot cast to timestamptz on assignment.
424 INSERT INTO caster (timestamptz) VALUES ('1999-01-08 04:05:06'::text);
425 INSERT INTO caster (text) VALUES ('1999-01-08 04:05:06'::timestamptz);
426 INSERT INTO caster (timestamptz) VALUES ('1999-01-08 04:05:06'::citext);
427 INSERT INTO caster (citext) VALUES ('1999-01-08 04:05:06'::timestamptz);
428
429 -- Cannot cast to interval on assignment.
430 INSERT INTO caster (interval) VALUES ('1 hour'::text);
431 INSERT INTO caster (text) VALUES ('1 hour'::interval);
432 INSERT INTO caster (interval) VALUES ('1 hour'::citext);
433 INSERT INTO caster (citext) VALUES ('1 hour'::interval);
434
435 -- Cannot cast to date on assignment.
436 INSERT INTO caster (date) VALUES ('1999-01-08'::text);
437 INSERT INTO caster (text) VALUES ('1999-01-08'::date);
438 INSERT INTO caster (date) VALUES ('1999-01-08'::citext);
439 INSERT INTO caster (citext) VALUES ('1999-01-08'::date);
440
441 -- Cannot cast to time on assignment.
442 INSERT INTO caster (time) VALUES ('04:05:06'::text);
443 INSERT INTO caster (text) VALUES ('04:05:06'::time);
444 INSERT INTO caster (time) VALUES ('04:05:06'::citext);
445 INSERT INTO caster (citext) VALUES ('04:05:06'::time);
446
447 -- Cannot cast to timetz on assignment.
448 INSERT INTO caster (timetz) VALUES ('04:05:06'::text);
449 INSERT INTO caster (text) VALUES ('04:05:06'::timetz);
450 INSERT INTO caster (timetz) VALUES ('04:05:06'::citext);
451 INSERT INTO caster (citext) VALUES ('04:05:06'::timetz);
452
453 -- Cannot cast to point on assignment.
454 INSERT INTO caster (point) VALUES ('( 1 , 1)'::text);
455 INSERT INTO caster (text) VALUES ('( 1 , 1)'::point);
456 INSERT INTO caster (point) VALUES ('( 1 , 1)'::citext);
457 INSERT INTO caster (citext) VALUES ('( 1 , 1)'::point);
458
459 -- Cannot cast to lseg on assignment.
460 INSERT INTO caster (lseg) VALUES ('( 1 , 1 ) , ( 2 , 2 )'::text);
461 INSERT INTO caster (text) VALUES ('( 1 , 1 ) , ( 2 , 2 )'::lseg);
462 INSERT INTO caster (lseg) VALUES ('( 1 , 1 ) , ( 2 , 2 )'::citext);
463 INSERT INTO caster (citext) VALUES ('( 1 , 1 ) , ( 2 , 2 )'::lseg);
464
465 -- Cannot cast to box on assignment.
466 INSERT INTO caster (box) VALUES ('(0,0),(1,1)'::text);
467 INSERT INTO caster (text) VALUES ('(0,0),(1,1)'::box);
468 INSERT INTO caster (box) VALUES ('(0,0),(1,1)'::citext);
469 INSERT INTO caster (citext) VALUES ('(0,0),(1,1)'::box);
470
471 -- Cannot cast to path on assignment.
472 INSERT INTO caster (path) VALUES ('((0,0),(1,1),(2,0))'::text);
473 INSERT INTO caster (text) VALUES ('((0,0),(1,1),(2,0))'::path);
474 INSERT INTO caster (path) VALUES ('((0,0),(1,1),(2,0))'::citext);
475 INSERT INTO caster (citext) VALUES ('((0,0),(1,1),(2,0))'::path);
476
477 -- Cannot cast to polygon on assignment.
478 INSERT INTO caster (polygon) VALUES ('((0,0),(1,1))'::text);
479 INSERT INTO caster (text) VALUES ('((0,0),(1,1))'::polygon);
480 INSERT INTO caster (polygon) VALUES ('((0,0),(1,1))'::citext);
481 INSERT INTO caster (citext) VALUES ('((0,0),(1,1))'::polygon);
482
483 -- Cannot cast to circle on assignment.
484 INSERT INTO caster (circle) VALUES ('((0,0),2)'::text);
485 INSERT INTO caster (text) VALUES ('((0,0),2)'::circle);
486 INSERT INTO caster (circle) VALUES ('((0,0),2)'::citext);
487 INSERT INTO caster (citext) VALUES ('((0,0),2)'::circle);
488
489 -- Cannot cast to bit on assignment.
490 INSERT INTO caster (bit) VALUES ('101'::text);
491 INSERT INTO caster (text) VALUES ('101'::bit);
492 INSERT INTO caster (bit) VALUES ('101'::citext);
493 INSERT INTO caster (citext) VALUES ('101'::bit);
494
495 -- Cannot cast to bit varying on assignment.
496 INSERT INTO caster (bitv) VALUES ('101'::text);
497 INSERT INTO caster (text) VALUES ('101'::bit varying);
498 INSERT INTO caster (bitv) VALUES ('101'::citext);
499 INSERT INTO caster (citext) VALUES ('101'::bit varying);
500
501 -- Cannot cast to tsvector on assignment.
502 INSERT INTO caster (tsvector) VALUES ('the fat cat'::text);
503 INSERT INTO caster (text) VALUES ('the fat cat'::tsvector);
504 INSERT INTO caster (tsvector) VALUES ('the fat cat'::citext);
505 INSERT INTO caster (citext) VALUES ('the fat cat'::tsvector);
506
507 -- Cannot cast to tsquery on assignment.
508 INSERT INTO caster (tsquery) VALUES ('fat & rat'::text);
509 INSERT INTO caster (text) VALUES ('fat & rat'::tsquery);
510 INSERT INTO caster (tsquery) VALUES ('fat & rat'::citext);
511 INSERT INTO caster (citext) VALUES ('fat & rat'::tsquery);
512
513 -- Cannot cast to uuid on assignment.
514 INSERT INTO caster (uuid) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::text);
515 INSERT INTO caster (text) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid);
516 INSERT INTO caster (uuid) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::citext);
517 INSERT INTO caster (citext) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid);
518
519 -- Table 9-5. SQL String Functions and Operators
520 SELECT 'D'::citext || 'avid'::citext = 'David'::citext AS citext_concat;
521 SELECT 'Value: '::citext || 42 = 'Value: 42' AS text_concat;
522 SELECT 42 || ': value'::citext ='42: value' AS int_concat;
523 SELECT bit_length('jose'::citext) = 32 AS t;
524 SELECT bit_length( name ) = bit_length( name::text ) AS t FROM srt;
525 SELECT textlen( name ) = textlen( name::text ) AS t FROM srt;
526 SELECT char_length( name ) = char_length( name::text ) AS t FROM srt;
527 SELECT lower( name ) = lower( name::text ) AS t FROM srt;
528 SELECT octet_length( name ) = octet_length( name::text ) AS t FROM srt;
529 SELECT overlay( name placing 'hom' from 2 for 4) = overlay( name::text placing 'hom' from 2 for 4) AS t FROM srt;
530 SELECT position( 'a' IN name ) = position( 'a' IN name::text ) AS t FROM srt;
531
532 SELECT substr('alphabet'::citext, 3) = 'phabet' AS t;
533 SELECT substr('alphabet'::citext, 3, 2) = 'ph' AS t;
534
535 SELECT substring('alphabet'::citext, 3) = 'phabet' AS t;
536 SELECT substring('alphabet'::citext, 3, 2) = 'ph' AS t;
537 SELECT substring('Thomas'::citext from 2 for 3) = 'hom' AS t;
538 SELECT substring('Thomas'::citext from 2) = 'homas' AS t;
539 SELECT substring('Thomas'::citext from '...$') = 'mas' AS t;
540 SELECT substring('Thomas'::citext similar '%#"o_a#"_' escape '#') = 'oma' AS t;
541
542 SELECT trim(' trim '::citext) = 'trim' AS t;
543 SELECT trim('xxxxxtrimxxxx'::citext, 'x'::citext) = 'trim' AS t;
544 SELECT trim('xxxxxxtrimxxxx'::text, 'x'::citext) = 'trim' AS t;
545 SELECT trim('xxxxxtrimxxxx'::text, 'x'::citext) = 'trim' AS t;
546
547 SELECT upper( name ) = upper( name::text ) AS t FROM srt;
548
549 -- Table 9-6. Other String Functions.
550 SELECT ascii( name ) = ascii( name::text ) AS t FROM srt;
551
552 SELECT btrim(' trim'::citext ) = 'trim' AS t;
553 SELECT btrim('xxxxxtrimxxxx'::citext, 'x'::citext ) = 'trim' AS t;
554 SELECT btrim('xyxtrimyyx'::citext, 'xy'::citext) = 'trim' AS t;
555 SELECT btrim('xyxtrimyyx'::text, 'xy'::citext) = 'trim' AS t;
556 SELECT btrim('xyxtrimyyx'::citext, 'xy'::text ) = 'trim' AS t;
557
558 -- chr() takes an int and returns text.
559 -- convert() and convert_from take bytea and return text.
560
561 SELECT convert_from( name::bytea, 'SQL_ASCII' ) = convert_from( name::text::bytea, 'SQL_ASCII' ) AS t FROM srt;
562 SELECT decode('MTIzAAE='::citext, 'base64') = decode('MTIzAAE='::text, 'base64') AS t;
563 -- encode() takes bytea and returns text.
564 SELECT initcap('hi THOMAS'::citext) = initcap('hi THOMAS'::text) AS t;
565 SELECT length( name ) = length( name::text ) AS t FROM srt;
566
567 SELECT lpad('hi'::citext, 5 ) = ' hi' AS t;
568 SELECT lpad('hi'::citext, 5, 'xy'::citext) = 'xyxhi' AS t;
569 SELECT lpad('hi'::text, 5, 'xy'::citext) = 'xyxhi' AS t;
570 SELECT lpad('hi'::citext, 5, 'xy'::text ) = 'xyxhi' AS t;
571
572 SELECT ltrim(' trim'::citext ) = 'trim' AS t;
573 SELECT ltrim('zzzytrim'::citext, 'xyz'::citext) = 'trim' AS t;
574 SELECT ltrim('zzzytrim'::text, 'xyz'::citext) = 'trim' AS t;
575 SELECT ltrim('zzzytrim'::citext, 'xyz'::text ) = 'trim' AS t;
576
577 -- pg_client_encoding() takes no args and returns name.
578 SELECT quote_ident( name ) = quote_ident( name::text ) AS t FROM srt;
579 SELECT quote_literal( name ) = quote_literal( name::text ) AS t FROM srt;
580
581 SELECT regexp_match('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
582 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
583 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
584 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
585 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
586 SELECT regexp_match('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
587 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
588 -- c forces case-sensitive
589 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no result";
590 -- g is not allowed
591 SELECT regexp_match('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g') AS "error";
592
593 SELECT regexp_matches('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
594 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
595 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
596 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
597 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
598 SELECT regexp_matches('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
599 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
600 -- c forces case-sensitive
601 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no rows";
602 -- g allows multiple output rows
603 SELECT regexp_matches('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g'::citext) AS "two rows";
604
605 SELECT regexp_replace('Thomas'::citext, '.[mN]a.', 'M') = 'ThM' AS t;
606 SELECT regexp_replace('Thomas'::citext, '.[MN]A.', 'M') = 'ThM' AS t;
607 SELECT regexp_replace('Thomas', '.[MN]A.'::citext, 'M') = 'ThM' AS t;
608 SELECT regexp_replace('Thomas'::citext, '.[MN]A.'::citext, 'M') = 'ThM' AS t;
609 -- c forces case-sensitive
610 SELECT regexp_replace('Thomas'::citext, '.[MN]A.'::citext, 'M', 'c') = 'Thomas' AS t;
611
612 SELECT regexp_split_to_array('hello world'::citext, E'\\s+') = ARRAY[ 'hello', 'world' ] AS t;
613 SELECT regexp_split_to_array('helloTworld'::citext, 't') = ARRAY[ 'hello', 'world' ] AS t;
614 SELECT regexp_split_to_array('helloTworld', 't'::citext) = ARRAY[ 'hello', 'world' ] AS t;
615 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext) = ARRAY[ 'hello', 'world' ] AS t;
616 SELECT regexp_split_to_array('helloTworld'::citext, 't', 's') = ARRAY[ 'hello', 'world' ] AS t;
617 SELECT regexp_split_to_array('helloTworld', 't'::citext, 's') = ARRAY[ 'hello', 'world' ] AS t;
618 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext, 's') = ARRAY[ 'hello', 'world' ] AS t;
619
620 -- c forces case-sensitive
621 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext, 'c') = ARRAY[ 'helloTworld' ] AS t;
622
623 SELECT regexp_split_to_table('hello world'::citext, E'\\s+') AS words;
624 SELECT regexp_split_to_table('helloTworld'::citext, 't') AS words;
625 SELECT regexp_split_to_table('helloTworld', 't'::citext) AS words;
626 SELECT regexp_split_to_table('helloTworld'::citext, 't'::citext) AS words;
627 -- c forces case-sensitive
628 SELECT regexp_split_to_table('helloTworld'::citext, 't'::citext, 'c') AS word;
629
630 SELECT repeat('Pg'::citext, 4) = 'PgPgPgPg' AS t;
631
632 SELECT replace('abcdefabcdef'::citext, 'cd', 'XX') = 'abXXefabXXef' AS t;
633 SELECT replace('abcdefabcdef'::citext, 'CD', 'XX') = 'abXXefabXXef' AS t;
634 SELECT replace('ab^is$abcdef'::citext, '^is$', 'XX') = 'abXXabcdef' AS t;
635 SELECT replace('abcdefabcdef', 'cd'::citext, 'XX') = 'abXXefabXXef' AS t;
636 SELECT replace('abcdefabcdef', 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
637 SELECT replace('ab^is$abcdef', '^is$'::citext, 'XX') = 'abXXabcdef' AS t;
638 SELECT replace('abcdefabcdef'::citext, 'cd'::citext, 'XX') = 'abXXefabXXef' AS t;
639 SELECT replace('abcdefabcdef'::citext, 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
640 SELECT replace('ab^is$abcdef'::citext, '^is$'::citext, 'XX') = 'abXXabcdef' AS t;
641
642 SELECT rpad('hi'::citext, 5 ) = 'hi ' AS t;
643 SELECT rpad('hi'::citext, 5, 'xy'::citext) = 'hixyx' AS t;
644 SELECT rpad('hi'::text, 5, 'xy'::citext) = 'hixyx' AS t;
645 SELECT rpad('hi'::citext, 5, 'xy'::text ) = 'hixyx' AS t;
646
647 SELECT rtrim('trim '::citext ) = 'trim' AS t;
648 SELECT rtrim('trimxxxx'::citext, 'x'::citext) = 'trim' AS t;
649 SELECT rtrim('trimxxxx'::text, 'x'::citext) = 'trim' AS t;
650 SELECT rtrim('trimxxxx'::text, 'x'::text ) = 'trim' AS t;
651
652 SELECT split_part('abc~@~def~@~ghi'::citext, '~@~', 2) = 'def' AS t;
653 SELECT split_part('abcTdefTghi'::citext, 't', 2) = 'def' AS t;
654 SELECT split_part('abcTdefTghi'::citext, 't'::citext, 2) = 'def' AS t;
655 SELECT split_part('abcTdefTghi', 't'::citext, 2) = 'def' AS t;
656
657 SELECT strpos('high'::citext, 'gh' ) = 3 AS t;
658 SELECT strpos('high', 'gh'::citext) = 3 AS t;
659 SELECT strpos('high'::citext, 'gh'::citext) = 3 AS t;
660 SELECT strpos('high'::citext, 'GH' ) = 3 AS t;
661 SELECT strpos('high', 'GH'::citext) = 3 AS t;
662 SELECT strpos('high'::citext, 'GH'::citext) = 3 AS t;
663
664 -- to_ascii() does not support UTF-8.
665 -- to_hex() takes a numeric argument.
666 SELECT substr('alphabet', 3, 2) = 'ph' AS t;
667 SELECT translate('abcdefabcdef'::citext, 'cd', 'XX') = 'abXXefabXXef' AS t;
668 SELECT translate('abcdefabcdef'::citext, 'CD', 'XX') = 'abXXefabXXef' AS t;
669 SELECT translate('abcdefabcdef'::citext, 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
670 SELECT translate('abcdefabcdef', 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
671
672 -- Table 9-20. Formatting Functions
673 SELECT to_date('05 Dec 2000'::citext, 'DD Mon YYYY'::citext)
674 = to_date('05 Dec 2000', 'DD Mon YYYY') AS t;
675 SELECT to_date('05 Dec 2000'::citext, 'DD Mon YYYY')
676 = to_date('05 Dec 2000', 'DD Mon YYYY') AS t;
677 SELECT to_date('05 Dec 2000', 'DD Mon YYYY'::citext)
678 = to_date('05 Dec 2000', 'DD Mon YYYY') AS t;
679
680 SELECT to_number('12,454.8-'::citext, '99G999D9S'::citext)
681 = to_number('12,454.8-', '99G999D9S') AS t;
682 SELECT to_number('12,454.8-'::citext, '99G999D9S')
683 = to_number('12,454.8-', '99G999D9S') AS t;
684 SELECT to_number('12,454.8-', '99G999D9S'::citext)
685 = to_number('12,454.8-', '99G999D9S') AS t;
686
687 SELECT to_timestamp('05 Dec 2000'::citext, 'DD Mon YYYY'::citext)
688 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
689 SELECT to_timestamp('05 Dec 2000'::citext, 'DD Mon YYYY')
690 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
691 SELECT to_timestamp('05 Dec 2000', 'DD Mon YYYY'::citext)
692 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
693
694 -- Try assigning function results to a column.
695 SELECT COUNT(*) = 8::bigint AS t FROM try;
696 INSERT INTO try
697 VALUES ( to_char( now()::timestamp, 'HH12:MI:SS') ),
698 ( to_char( now() + '1 sec'::interval, 'HH12:MI:SS') ), -- timestamptz
699 ( to_char( '15h 2m 12s'::interval, 'HH24:MI:SS') ),
700 ( to_char( current_date, '999') ),
701 ( to_char( 125::int, '999') ),
702 ( to_char( 127::int4, '999') ),
703 ( to_char( 126::int8, '999') ),
704 ( to_char( 128.8::real, '999D9') ),
705 ( to_char( 125.7::float4, '999D9') ),
706 ( to_char( 125.9::float8, '999D9') ),
707 ( to_char( -125.8::numeric, '999D99S') );
708
709 SELECT COUNT(*) = 19::bigint AS t FROM try;
710
711 SELECT like_escape( name, '' ) = like_escape( name::text, '' ) AS t FROM srt;
712 SELECT like_escape( name::text, ''::citext ) = like_escape( name::text, '' ) AS t FROM srt;
713
714 -- Ensure correct behavior for citext with materialized views.
715 CREATE TABLE citext_table (
716 id serial primary key,
717 name citext
718 );
719 INSERT INTO citext_table (name)
720 VALUES ('one'), ('two'), ('three'), (NULL), (NULL);
721 CREATE MATERIALIZED VIEW citext_matview AS
722 SELECT * FROM citext_table;
723 CREATE UNIQUE INDEX citext_matview_id
724 ON citext_matview (id);
725 SELECT *
726 FROM citext_matview m
727 FULL JOIN citext_table t ON (t.id = m.id AND t *= m)
728 WHERE t.id IS NULL OR m.id IS NULL;
729 UPDATE citext_table SET name = 'Two' WHERE name = 'TWO';
730 SELECT *
731 FROM citext_matview m
732 FULL JOIN citext_table t ON (t.id = m.id AND t *= m)
733 WHERE t.id IS NULL OR m.id IS NULL;
734 REFRESH MATERIALIZED VIEW CONCURRENTLY citext_matview;
735 SELECT * FROM citext_matview ORDER BY id;
736
737 -- test citext_pattern_cmp() function explicitly.
738 SELECT citext_pattern_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
739 SELECT citext_pattern_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
740 SELECT citext_pattern_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
741 SELECT citext_pattern_cmp('B'::citext, 'a'::citext) > 0 AS true;
742 SELECT citext_pattern_cmp('a'::citext, 'B'::citext) < 0 AS true;
743 SELECT citext_pattern_cmp('A'::citext, 'b'::citext) < 0 AS true;
744 SELECT citext_pattern_cmp('ABCD'::citext, 'abc'::citext) > 0 AS true;
745 SELECT citext_pattern_cmp('ABC'::citext, 'abcd'::citext) < 0 AS true;
746
747 -- test operator functions
748 -- lt
749 SELECT citext_pattern_lt('a'::citext, 'b'::citext) AS true;
750 SELECT citext_pattern_lt('A'::citext, 'b'::citext) AS true;
751 SELECT citext_pattern_lt('a'::citext, 'B'::citext) AS true;
752 SELECT citext_pattern_lt('b'::citext, 'a'::citext) AS false;
753 SELECT citext_pattern_lt('B'::citext, 'a'::citext) AS false;
754 SELECT citext_pattern_lt('b'::citext, 'A'::citext) AS false;
755 -- le
756 SELECT citext_pattern_le('a'::citext, 'a'::citext) AS true;
757 SELECT citext_pattern_le('a'::citext, 'A'::citext) AS true;
758 SELECT citext_pattern_le('A'::citext, 'a'::citext) AS true;
759 SELECT citext_pattern_le('A'::citext, 'A'::citext) AS true;
760 SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
761 SELECT citext_pattern_le('A'::citext, 'b'::citext) AS true;
762 SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
763 SELECT citext_pattern_le('b'::citext, 'a'::citext) AS false;
764 SELECT citext_pattern_le('B'::citext, 'a'::citext) AS false;
765 SELECT citext_pattern_le('b'::citext, 'A'::citext) AS false;
766 -- gt
767 SELECT citext_pattern_gt('a'::citext, 'b'::citext) AS false;
768 SELECT citext_pattern_gt('A'::citext, 'b'::citext) AS false;
769 SELECT citext_pattern_gt('a'::citext, 'B'::citext) AS false;
770 SELECT citext_pattern_gt('b'::citext, 'a'::citext) AS true;
771 SELECT citext_pattern_gt('B'::citext, 'a'::citext) AS true;
772 SELECT citext_pattern_gt('b'::citext, 'A'::citext) AS true;
773 -- ge
774 SELECT citext_pattern_ge('a'::citext, 'a'::citext) AS true;
775 SELECT citext_pattern_ge('a'::citext, 'A'::citext) AS true;
776 SELECT citext_pattern_ge('A'::citext, 'a'::citext) AS true;
777 SELECT citext_pattern_ge('A'::citext, 'A'::citext) AS true;
778 SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
779 SELECT citext_pattern_ge('A'::citext, 'b'::citext) AS false;
780 SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
781 SELECT citext_pattern_ge('b'::citext, 'a'::citext) AS true;
782 SELECT citext_pattern_ge('B'::citext, 'a'::citext) AS true;
783 SELECT citext_pattern_ge('b'::citext, 'A'::citext) AS true;
784
785 -- Test ~<~ and ~<=~
786 SELECT 'a'::citext ~<~ 'B'::citext AS t;
787 SELECT 'b'::citext ~<~ 'A'::citext AS f;
788 SELECT 'a'::citext ~<=~ 'B'::citext AS t;
789 SELECT 'a'::citext ~<=~ 'A'::citext AS t;
790
791 -- Test ~>~ and ~>=~
792 SELECT 'B'::citext ~>~ 'a'::citext AS t;
793 SELECT 'b'::citext ~>~ 'A'::citext AS t;
794 SELECT 'B'::citext ~>~ 'b'::citext AS f;
795 SELECT 'B'::citext ~>=~ 'b'::citext AS t;
796
797 -- Test implicit casting. citext casts to text, but not vice-versa.
798 SELECT 'B'::citext ~<~ 'a'::text AS t; -- text wins.
799 SELECT 'B'::citext ~<=~ 'a'::text AS t; -- text wins.
800
801 SELECT 'a'::citext ~>~ 'B'::text AS t; -- text wins.
802 SELECT 'a'::citext ~>=~ 'B'::text AS t; -- text wins.
803
804 -- Test implicit casting. citext casts to varchar, but not vice-versa.
805 SELECT 'B'::citext ~<~ 'a'::varchar AS t; -- varchar wins.
806 SELECT 'B'::citext ~<=~ 'a'::varchar AS t; -- varchar wins.
807
808 SELECT 'a'::citext ~>~ 'B'::varchar AS t; -- varchar wins.
809 SELECT 'a'::citext ~>=~ 'B'::varchar AS t; -- varchar wins.