Debian Codegraph @

contrib/citext/expected/citext_1.out

raw
1 --
2 -- Test citext datatype
3 --
4 CREATE EXTENSION citext;
5 -- Check whether any of our opclasses fail amvalidate
6 SELECT amname, opcname
7 FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
8 WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
9 amname | opcname
10 --------+---------
11 (0 rows)
12
13 -- Test the operators and indexing functions
14 -- Test = and <>.
15 SELECT 'a'::citext = 'a'::citext AS t;
16 t
17 ---
18 t
19 (1 row)
20
21 SELECT 'a'::citext = 'A'::citext AS t;
22 t
23 ---
24 t
25 (1 row)
26
27 SELECT 'a'::citext = 'A'::text AS f; -- text wins the discussion
28 f
29 ---
30 f
31 (1 row)
32
33 SELECT 'a'::citext = 'b'::citext AS f;
34 f
35 ---
36 f
37 (1 row)
38
39 SELECT 'a'::citext = 'ab'::citext AS f;
40 f
41 ---
42 f
43 (1 row)
44
45 SELECT 'a'::citext <> 'ab'::citext AS t;
46 t
47 ---
48 t
49 (1 row)
50
51 -- Test > and >=
52 SELECT 'B'::citext > 'a'::citext AS t;
53 t
54 ---
55 t
56 (1 row)
57
58 SELECT 'b'::citext > 'A'::citext AS t;
59 t
60 ---
61 t
62 (1 row)
63
64 SELECT 'B'::citext > 'b'::citext AS f;
65 f
66 ---
67 f
68 (1 row)
69
70 SELECT 'B'::citext >= 'b'::citext AS t;
71 t
72 ---
73 t
74 (1 row)
75
76 -- Test < and <=
77 SELECT 'a'::citext < 'B'::citext AS t;
78 t
79 ---
80 t
81 (1 row)
82
83 SELECT 'a'::citext <= 'B'::citext AS t;
84 t
85 ---
86 t
87 (1 row)
88
89 -- Test implicit casting. citext casts to text, but not vice-versa.
90 SELECT 'a'::citext = 'a'::text AS t;
91 t
92 ---
93 t
94 (1 row)
95
96 SELECT 'A'::text <> 'a'::citext AS t;
97 t
98 ---
99 t
100 (1 row)
101
102 SELECT 'B'::citext < 'a'::text AS t; -- text wins.
103 t
104 ---
105 f
106 (1 row)
107
108 SELECT 'B'::citext <= 'a'::text AS t; -- text wins.
109 t
110 ---
111 f
112 (1 row)
113
114 SELECT 'a'::citext > 'B'::text AS t; -- text wins.
115 t
116 ---
117 f
118 (1 row)
119
120 SELECT 'a'::citext >= 'B'::text AS t; -- text wins.
121 t
122 ---
123 f
124 (1 row)
125
126 -- Test implicit casting. citext casts to varchar, but not vice-versa.
127 SELECT 'a'::citext = 'a'::varchar AS t;
128 t
129 ---
130 t
131 (1 row)
132
133 SELECT 'A'::varchar <> 'a'::citext AS t;
134 t
135 ---
136 t
137 (1 row)
138
139 SELECT 'B'::citext < 'a'::varchar AS t; -- varchar wins.
140 t
141 ---
142 f
143 (1 row)
144
145 SELECT 'B'::citext <= 'a'::varchar AS t; -- varchar wins.
146 t
147 ---
148 f
149 (1 row)
150
151 SELECT 'a'::citext > 'B'::varchar AS t; -- varchar wins.
152 t
153 ---
154 f
155 (1 row)
156
157 SELECT 'a'::citext >= 'B'::varchar AS t; -- varchar wins.
158 t
159 ---
160 f
161 (1 row)
162
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;
166 t
167 ---
168 t
169 (1 row)
170
171 SELECT 'aardvark'::citext = 'aardVark'::citext AS t;
172 t
173 ---
174 t
175 (1 row)
176
177 -- Check the citext_cmp() function explicitly.
178 SELECT citext_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
179 zero
180 ------
181 0
182 (1 row)
183
184 SELECT citext_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
185 zero
186 ------
187 0
188 (1 row)
189
190 SELECT citext_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
191 zero
192 ------
193 0
194 (1 row)
195
196 SELECT citext_cmp('B'::citext, 'a'::citext) > 0 AS true;
197 true
198 ------
199 t
200 (1 row)
201
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 -------+----------+-----------+-----------
212 (0 rows)
213
214 -- Do some tests using a table and index.
215 CREATE TEMP TABLE try (
216 name citext PRIMARY KEY
217 );
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 <> 'â';
221 name | eq_a
222 ------+------
223 a | t
224 ab | f
225 aba | f
226 b | f
227 ba | f
228 bab | f
229 AZ | f
230 (7 rows)
231
232 SELECT name, 'a' = name AS t FROM try where name = 'a';
233 name | t
234 ------+---
235 a | t
236 (1 row)
237
238 SELECT name, 'A' = name AS "eq_A" FROM try WHERE name <> 'â';
239 name | eq_A
240 ------+------
241 a | t
242 ab | f
243 aba | f
244 b | f
245 ba | f
246 bab | f
247 AZ | f
248 (7 rows)
249
250 SELECT name, 'A' = name AS t FROM try where name = 'A';
251 name | t
252 ------+---
253 a | t
254 (1 row)
255
256 SELECT name, 'A' = name AS t FROM try where name = 'A';
257 name | t
258 ------+---
259 a | t
260 (1 row)
261
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;
274 t
275 ---
276 t
277 (1 row)
278
279 SELECT citext_smaller( 'ABC'::citext, 'bbbb'::citext ) = 'ABC' AS t;
280 t
281 ---
282 t
283 (1 row)
284
285 SELECT citext_smaller( 'aardvark'::citext, 'Aaba'::citext ) = 'Aaba' AS t;
286 t
287 ---
288 t
289 (1 row)
290
291 SELECT citext_smaller( 'aardvark'::citext, 'AARDVARK'::citext ) = 'AARDVARK' AS t;
292 t
293 ---
294 t
295 (1 row)
296
297 SELECT citext_larger( 'ab'::citext, 'ac'::citext ) = 'ac' AS t;
298 t
299 ---
300 t
301 (1 row)
302
303 SELECT citext_larger( 'ABC'::citext, 'bbbb'::citext ) = 'bbbb' AS t;
304 t
305 ---
306 t
307 (1 row)
308
309 SELECT citext_larger( 'aardvark'::citext, 'Aaba'::citext ) = 'aardvark' AS t;
310 t
311 ---
312 t
313 (1 row)
314
315 -- Test aggregate functions and sort ordering
316 CREATE TEMP TABLE srt (
317 name CITEXT
318 );
319 INSERT INTO srt (name)
320 VALUES ('abb'),
321 ('ABA'),
322 ('ABC'),
323 ('abd');
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;
328 ABA
329 -----
330 ABA
331 (1 row)
332
333 SELECT MAX(name) AS abd FROM srt;
334 abd
335 -----
336 abd
337 (1 row)
338
339 reset enable_seqscan;
340 set enable_indexscan = off;
341 SELECT MIN(name) AS "ABA" FROM srt;
342 ABA
343 -----
344 ABA
345 (1 row)
346
347 SELECT MAX(name) AS abd FROM srt;
348 abd
349 -----
350 abd
351 (1 row)
352
353 reset enable_indexscan;
354 -- Check sorting likewise
355 set enable_seqscan = off;
356 SELECT name FROM srt ORDER BY name;
357 name
358 ------
359 ABA
360 abb
361 ABC
362 abd
363 (4 rows)
364
365 reset enable_seqscan;
366 set enable_indexscan = off;
367 SELECT name FROM srt ORDER BY name;
368 name
369 ------
370 ABA
371 abb
372 ABC
373 abd
374 (4 rows)
375
376 reset enable_indexscan;
377 -- Test assignment casts.
378 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::text;
379 aba
380 -----
381 aba
382 (1 row)
383
384 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::varchar;
385 aba
386 -----
387 aba
388 (1 row)
389
390 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::bpchar;
391 aba
392 -----
393 aba
394 (1 row)
395
396 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA';
397 aba
398 -----
399 aba
400 (1 row)
401
402 SELECT LOWER(name) as aba FROM srt WHERE name = 'ABA'::citext;
403 aba
404 -----
405 aba
406 (1 row)
407
408 -- LIKE should be case-insensitive
409 SELECT name FROM srt WHERE name LIKE '%a%' ORDER BY name;
410 name
411 ------
412 ABA
413 abb
414 ABC
415 abd
416 (4 rows)
417
418 SELECT name FROM srt WHERE name NOT LIKE '%b%' ORDER BY name;
419 name
420 ------
421 (0 rows)
422
423 SELECT name FROM srt WHERE name LIKE '%A%' ORDER BY name;
424 name
425 ------
426 ABA
427 abb
428 ABC
429 abd
430 (4 rows)
431
432 SELECT name FROM srt WHERE name NOT LIKE '%B%' ORDER BY name;
433 name
434 ------
435 (0 rows)
436
437 -- ~~ should be case-insensitive
438 SELECT name FROM srt WHERE name ~~ '%a%' ORDER BY name;
439 name
440 ------
441 ABA
442 abb
443 ABC
444 abd
445 (4 rows)
446
447 SELECT name FROM srt WHERE name !~~ '%b%' ORDER BY name;
448 name
449 ------
450 (0 rows)
451
452 SELECT name FROM srt WHERE name ~~ '%A%' ORDER BY name;
453 name
454 ------
455 ABA
456 abb
457 ABC
458 abd
459 (4 rows)
460
461 SELECT name FROM srt WHERE name !~~ '%B%' ORDER BY name;
462 name
463 ------
464 (0 rows)
465
466 -- ~ should be case-insensitive
467 SELECT name FROM srt WHERE name ~ '^a' ORDER BY name;
468 name
469 ------
470 ABA
471 abb
472 ABC
473 abd
474 (4 rows)
475
476 SELECT name FROM srt WHERE name !~ 'a$' ORDER BY name;
477 name
478 ------
479 abb
480 ABC
481 abd
482 (3 rows)
483
484 SELECT name FROM srt WHERE name ~ '^A' ORDER BY name;
485 name
486 ------
487 ABA
488 abb
489 ABC
490 abd
491 (4 rows)
492
493 SELECT name FROM srt WHERE name !~ 'A$' ORDER BY name;
494 name
495 ------
496 abb
497 ABC
498 abd
499 (3 rows)
500
501 -- SIMILAR TO should be case-insensitive.
502 SELECT name FROM srt WHERE name SIMILAR TO '%a.*';
503 name
504 ------
505 ABA
506 (1 row)
507
508 SELECT name FROM srt WHERE name SIMILAR TO '%A.*';
509 name
510 ------
511 ABA
512 (1 row)
513
514 -- Explicit casts.
515 SELECT true::citext = 'true' AS t;
516 t
517 ---
518 t
519 (1 row)
520
521 SELECT 'true'::citext::boolean = true AS t;
522 t
523 ---
524 t
525 (1 row)
526
527 SELECT 4::citext = '4' AS t;
528 t
529 ---
530 t
531 (1 row)
532
533 SELECT 4::int4::citext = '4' AS t;
534 t
535 ---
536 t
537 (1 row)
538
539 SELECT '4'::citext::int4 = 4 AS t;
540 t
541 ---
542 t
543 (1 row)
544
545 SELECT 4::integer::citext = '4' AS t;
546 t
547 ---
548 t
549 (1 row)
550
551 SELECT '4'::citext::integer = 4 AS t;
552 t
553 ---
554 t
555 (1 row)
556
557 SELECT 4::int8::citext = '4' AS t;
558 t
559 ---
560 t
561 (1 row)
562
563 SELECT '4'::citext::int8 = 4 AS t;
564 t
565 ---
566 t
567 (1 row)
568
569 SELECT 4::bigint::citext = '4' AS t;
570 t
571 ---
572 t
573 (1 row)
574
575 SELECT '4'::citext::bigint = 4 AS t;
576 t
577 ---
578 t
579 (1 row)
580
581 SELECT 4::int2::citext = '4' AS t;
582 t
583 ---
584 t
585 (1 row)
586
587 SELECT '4'::citext::int2 = 4 AS t;
588 t
589 ---
590 t
591 (1 row)
592
593 SELECT 4::smallint::citext = '4' AS t;
594 t
595 ---
596 t
597 (1 row)
598
599 SELECT '4'::citext::smallint = 4 AS t;
600 t
601 ---
602 t
603 (1 row)
604
605 SELECT 4.0::numeric = '4.0' AS t;
606 t
607 ---
608 t
609 (1 row)
610
611 SELECT '4.0'::citext::numeric = 4.0 AS t;
612 t
613 ---
614 t
615 (1 row)
616
617 SELECT 4.0::decimal = '4.0' AS t;
618 t
619 ---
620 t
621 (1 row)
622
623 SELECT '4.0'::citext::decimal = 4.0 AS t;
624 t
625 ---
626 t
627 (1 row)
628
629 SELECT 4.0::real = '4.0' AS t;
630 t
631 ---
632 t
633 (1 row)
634
635 SELECT '4.0'::citext::real = 4.0 AS t;
636 t
637 ---
638 t
639 (1 row)
640
641 SELECT 4.0::float4 = '4.0' AS t;
642 t
643 ---
644 t
645 (1 row)
646
647 SELECT '4.0'::citext::float4 = 4.0 AS t;
648 t
649 ---
650 t
651 (1 row)
652
653 SELECT 4.0::double precision = '4.0' AS t;
654 t
655 ---
656 t
657 (1 row)
658
659 SELECT '4.0'::citext::double precision = 4.0 AS t;
660 t
661 ---
662 t
663 (1 row)
664
665 SELECT 4.0::float8 = '4.0' AS t;
666 t
667 ---
668 t
669 (1 row)
670
671 SELECT '4.0'::citext::float8 = 4.0 AS t;
672 t
673 ---
674 t
675 (1 row)
676
677 SELECT 'foo'::name::citext = 'foo' AS t;
678 t
679 ---
680 t
681 (1 row)
682
683 SELECT 'foo'::citext::name = 'foo'::name AS t;
684 t
685 ---
686 t
687 (1 row)
688
689 SELECT 'f'::char::citext = 'f' AS t;
690 t
691 ---
692 t
693 (1 row)
694
695 SELECT 'f'::citext::char = 'f'::char AS t;
696 t
697 ---
698 t
699 (1 row)
700
701 SELECT 'f'::"char"::citext = 'f' AS t;
702 t
703 ---
704 t
705 (1 row)
706
707 SELECT 'f'::citext::"char" = 'f'::"char" AS t;
708 t
709 ---
710 t
711 (1 row)
712
713 SELECT '100'::money::citext = '$100.00' AS t;
714 t
715 ---
716 t
717 (1 row)
718
719 SELECT '100'::citext::money = '100'::money AS t;
720 t
721 ---
722 t
723 (1 row)
724
725 SELECT 'a'::char::citext = 'a' AS t;
726 t
727 ---
728 t
729 (1 row)
730
731 SELECT 'a'::citext::char = 'a'::char AS t;
732 t
733 ---
734 t
735 (1 row)
736
737 SELECT 'foo'::varchar::citext = 'foo' AS t;
738 t
739 ---
740 t
741 (1 row)
742
743 SELECT 'foo'::citext::varchar = 'foo'::varchar AS t;
744 t
745 ---
746 t
747 (1 row)
748
749 SELECT 'foo'::text::citext = 'foo' AS t;
750 t
751 ---
752 t
753 (1 row)
754
755 SELECT 'foo'::citext::text = 'foo'::text AS t;
756 t
757 ---
758 t
759 (1 row)
760
761 SELECT '192.168.100.128/25'::cidr::citext = '192.168.100.128/25' AS t;
762 t
763 ---
764 t
765 (1 row)
766
767 SELECT '192.168.100.128/25'::citext::cidr = '192.168.100.128/25'::cidr AS t;
768 t
769 ---
770 t
771 (1 row)
772
773 SELECT '192.168.100.128'::inet::citext = '192.168.100.128/32' AS t;
774 t
775 ---
776 t
777 (1 row)
778
779 SELECT '192.168.100.128'::citext::inet = '192.168.100.128'::inet AS t;
780 t
781 ---
782 t
783 (1 row)
784
785 SELECT '08:00:2b:01:02:03'::macaddr::citext = '08:00:2b:01:02:03' AS t;
786 t
787 ---
788 t
789 (1 row)
790
791 SELECT '08:00:2b:01:02:03'::citext::macaddr = '08:00:2b:01:02:03'::macaddr AS t;
792 t
793 ---
794 t
795 (1 row)
796
797 SELECT '1999-01-08 04:05:06'::timestamp::citext = '1999-01-08 04:05:06'::timestamp::text AS t;
798 t
799 ---
800 t
801 (1 row)
802
803 SELECT '1999-01-08 04:05:06'::citext::timestamp = '1999-01-08 04:05:06'::timestamp AS t;
804 t
805 ---
806 t
807 (1 row)
808
809 SELECT '1999-01-08 04:05:06'::timestamptz::citext = '1999-01-08 04:05:06'::timestamptz::text AS t;
810 t
811 ---
812 t
813 (1 row)
814
815 SELECT '1999-01-08 04:05:06'::citext::timestamptz = '1999-01-08 04:05:06'::timestamptz AS t;
816 t
817 ---
818 t
819 (1 row)
820
821 SELECT '1 hour'::interval::citext = '1 hour'::interval::text AS t;
822 t
823 ---
824 t
825 (1 row)
826
827 SELECT '1 hour'::citext::interval = '1 hour'::interval AS t;
828 t
829 ---
830 t
831 (1 row)
832
833 SELECT '1999-01-08'::date::citext = '1999-01-08'::date::text AS t;
834 t
835 ---
836 t
837 (1 row)
838
839 SELECT '1999-01-08'::citext::date = '1999-01-08'::date AS t;
840 t
841 ---
842 t
843 (1 row)
844
845 SELECT '04:05:06'::time::citext = '04:05:06' AS t;
846 t
847 ---
848 t
849 (1 row)
850
851 SELECT '04:05:06'::citext::time = '04:05:06'::time AS t;
852 t
853 ---
854 t
855 (1 row)
856
857 SELECT '04:05:06'::timetz::citext = '04:05:06'::timetz::text AS t;
858 t
859 ---
860 t
861 (1 row)
862
863 SELECT '04:05:06'::citext::timetz = '04:05:06'::timetz AS t;
864 t
865 ---
866 t
867 (1 row)
868
869 SELECT '( 1 , 1)'::point::citext = '(1,1)' AS t;
870 t
871 ---
872 t
873 (1 row)
874
875 SELECT '( 1 , 1)'::citext::point ~= '(1,1)'::point AS t;
876 t
877 ---
878 t
879 (1 row)
880
881 SELECT '( 1 , 1 ) , ( 2 , 2 )'::lseg::citext = '[(1,1),(2,2)]' AS t;
882 t
883 ---
884 t
885 (1 row)
886
887 SELECT '( 1 , 1 ) , ( 2 , 2 )'::citext::lseg = '[(1,1),(2,2)]'::lseg AS t;
888 t
889 ---
890 t
891 (1 row)
892
893 SELECT '( 0 , 0 ) , ( 1 , 1 )'::box::citext = '(0,0),(1,1)'::box::text AS t;
894 t
895 ---
896 t
897 (1 row)
898
899 SELECT '( 0 , 0 ) , ( 1 , 1 )'::citext::box ~= '(0,0),(1,1)'::text::box AS t;
900 t
901 ---
902 t
903 (1 row)
904
905 SELECT '((0,0),(1,1),(2,0))'::path::citext = '((0,0),(1,1),(2,0))' AS t;
906 t
907 ---
908 t
909 (1 row)
910
911 SELECT '((0,0),(1,1),(2,0))'::citext::path = '((0,0),(1,1),(2,0))'::path AS t;
912 t
913 ---
914 t
915 (1 row)
916
917 SELECT '((0,0),(1,1))'::polygon::citext = '((0,0),(1,1))' AS t;
918 t
919 ---
920 t
921 (1 row)
922
923 SELECT '((0,0),(1,1))'::citext::polygon ~= '((0,0),(1,1))'::polygon AS t;
924 t
925 ---
926 t
927 (1 row)
928
929 SELECT '((0,0),2)'::circle::citext = '((0,0),2)'::circle::text AS t;
930 t
931 ---
932 t
933 (1 row)
934
935 SELECT '((0,0),2)'::citext::circle ~= '((0,0),2)'::text::circle AS t;
936 t
937 ---
938 t
939 (1 row)
940
941 SELECT '101'::bit::citext = '101'::bit::text AS t;
942 t
943 ---
944 t
945 (1 row)
946
947 SELECT '101'::citext::bit = '101'::text::bit AS t;
948 t
949 ---
950 t
951 (1 row)
952
953 SELECT '101'::bit varying::citext = '101'::bit varying::text AS t;
954 t
955 ---
956 t
957 (1 row)
958
959 SELECT '101'::citext::bit varying = '101'::text::bit varying AS t;
960 t
961 ---
962 t
963 (1 row)
964
965 SELECT 'a fat cat'::tsvector::citext = '''a'' ''cat'' ''fat''' AS t;
966 t
967 ---
968 t
969 (1 row)
970
971 SELECT 'a fat cat'::citext::tsvector = 'a fat cat'::tsvector AS t;
972 t
973 ---
974 t
975 (1 row)
976
977 SELECT 'fat & rat'::tsquery::citext = '''fat'' & ''rat''' AS t;
978 t
979 ---
980 t
981 (1 row)
982
983 SELECT 'fat & rat'::citext::tsquery = 'fat & rat'::tsquery AS t;
984 t
985 ---
986 t
987 (1 row)
988
989 SELECT 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid::citext = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' AS t;
990 t
991 ---
992 t
993 (1 row)
994
995 SELECT 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::citext::uuid = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid AS t;
996 t
997 ---
998 t
999 (1 row)
1000
1001 CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
1002 SELECT 'sad'::mood::citext = 'sad' AS t;
1003 t
1004 ---
1005 t
1006 (1 row)
1007
1008 SELECT 'sad'::citext::mood = 'sad'::mood AS t;
1009 t
1010 ---
1011 t
1012 (1 row)
1013
1014 -- Assignment casts.
1015 CREATE TABLE caster (
1016 citext citext,
1017 text text,
1018 varchar varchar,
1019 bpchar bpchar,
1020 char char,
1021 chr "char",
1022 name name,
1023 bytea bytea,
1024 boolean boolean,
1025 float4 float4,
1026 float8 float8,
1027 numeric numeric,
1028 int8 int8,
1029 int4 int4,
1030 int2 int2,
1031 cidr cidr,
1032 inet inet,
1033 macaddr macaddr,
1034 money money,
1035 timestamp timestamp,
1036 timestamptz timestamptz,
1037 interval interval,
1038 date date,
1039 time time,
1040 timetz timetz,
1041 point point,
1042 lseg lseg,
1043 box box,
1044 path path,
1045 polygon polygon,
1046 circle circle,
1047 bit bit,
1048 bitv bit varying,
1049 tsvector tsvector,
1050 tsquery tsquery,
1051 uuid uuid
1052 );
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);
1072 ^
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);
1084 ^
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);
1090 ^
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);
1097 ^
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);
1103 ^
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);
1110 ^
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);
1116 ^
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);
1123 ^
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);
1129 ^
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);
1136 ^
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);
1142 ^
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);
1149 ^
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);
1155 ^
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);
1162 ^
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);
1168 ^
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);
1175 ^
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);
1181 ^
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/...
1188 ^
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/...
1194 ^
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'...
1201 ^
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'...
1207 ^
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...
1214 ^
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...
1220 ^
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);
1227 ^
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);
1233 ^
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...
1240 ^
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...
1246 ^
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...
1253 ^
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...
1259 ^
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);
1266 ^
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)...
1272 ^
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...
1279 ^
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...
1285 ^
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)...
1292 ^
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...
1298 ^
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)...
1305 ^
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...
1311 ^
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)...
1318 ^
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...
1324 ^
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 ...
1331 ^
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 ...
1337 ^
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...
1344 ^
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...
1350 ^
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,...
1357 ^
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,...
1363 ^
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))'::...
1370 ^
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))'::...
1376 ^
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...
1383 ^
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...
1389 ^
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);
1396 ^
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);
1402 ^
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);
1409 ^
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);
1415 ^
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...
1422 ^
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...
1428 ^
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...
1435 ^
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...
1441 ^
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...
1448 ^
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...
1454 ^
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;
1459 citext_concat
1460 ---------------
1461 t
1462 (1 row)
1463
1464 SELECT 'Value: '::citext || 42 = 'Value: 42' AS text_concat;
1465 text_concat
1466 -------------
1467 t
1468 (1 row)
1469
1470 SELECT 42 || ': value'::citext ='42: value' AS int_concat;
1471 int_concat
1472 ------------
1473 t
1474 (1 row)
1475
1476 SELECT bit_length('jose'::citext) = 32 AS t;
1477 t
1478 ---
1479 t
1480 (1 row)
1481
1482 SELECT bit_length( name ) = bit_length( name::text ) AS t FROM srt;
1483 t
1484 ---
1485 t
1486 t
1487 t
1488 t
1489 (4 rows)
1490
1491 SELECT textlen( name ) = textlen( name::text ) AS t FROM srt;
1492 t
1493 ---
1494 t
1495 t
1496 t
1497 t
1498 (4 rows)
1499
1500 SELECT char_length( name ) = char_length( name::text ) AS t FROM srt;
1501 t
1502 ---
1503 t
1504 t
1505 t
1506 t
1507 (4 rows)
1508
1509 SELECT lower( name ) = lower( name::text ) AS t FROM srt;
1510 t
1511 ---
1512 t
1513 t
1514 t
1515 t
1516 (4 rows)
1517
1518 SELECT octet_length( name ) = octet_length( name::text ) AS t FROM srt;
1519 t
1520 ---
1521 t
1522 t
1523 t
1524 t
1525 (4 rows)
1526
1527 SELECT overlay( name placing 'hom' from 2 for 4) = overlay( name::text placing 'hom' from 2 for 4) AS t FROM srt;
1528 t
1529 ---
1530 t
1531 t
1532 t
1533 t
1534 (4 rows)
1535
1536 SELECT position( 'a' IN name ) = position( 'a' IN name::text ) AS t FROM srt;
1537 t
1538 ---
1539 t
1540 t
1541 t
1542 t
1543 (4 rows)
1544
1545 SELECT substr('alphabet'::citext, 3) = 'phabet' AS t;
1546 t
1547 ---
1548 t
1549 (1 row)
1550
1551 SELECT substr('alphabet'::citext, 3, 2) = 'ph' AS t;
1552 t
1553 ---
1554 t
1555 (1 row)
1556
1557 SELECT substring('alphabet'::citext, 3) = 'phabet' AS t;
1558 t
1559 ---
1560 t
1561 (1 row)
1562
1563 SELECT substring('alphabet'::citext, 3, 2) = 'ph' AS t;
1564 t
1565 ---
1566 t
1567 (1 row)
1568
1569 SELECT substring('Thomas'::citext from 2 for 3) = 'hom' AS t;
1570 t
1571 ---
1572 t
1573 (1 row)
1574
1575 SELECT substring('Thomas'::citext from 2) = 'homas' AS t;
1576 t
1577 ---
1578 t
1579 (1 row)
1580
1581 SELECT substring('Thomas'::citext from '...$') = 'mas' AS t;
1582 t
1583 ---
1584 t
1585 (1 row)
1586
1587 SELECT substring('Thomas'::citext similar '%#"o_a#"_' escape '#') = 'oma' AS t;
1588 t
1589 ---
1590 t
1591 (1 row)
1592
1593 SELECT trim(' trim '::citext) = 'trim' AS t;
1594 t
1595 ---
1596 t
1597 (1 row)
1598
1599 SELECT trim('xxxxxtrimxxxx'::citext, 'x'::citext) = 'trim' AS t;
1600 t
1601 ---
1602 t
1603 (1 row)
1604
1605 SELECT trim('xxxxxxtrimxxxx'::text, 'x'::citext) = 'trim' AS t;
1606 t
1607 ---
1608 t
1609 (1 row)
1610
1611 SELECT trim('xxxxxtrimxxxx'::text, 'x'::citext) = 'trim' AS t;
1612 t
1613 ---
1614 t
1615 (1 row)
1616
1617 SELECT upper( name ) = upper( name::text ) AS t FROM srt;
1618 t
1619 ---
1620 t
1621 t
1622 t
1623 t
1624 (4 rows)
1625
1626 -- Table 9-6. Other String Functions.
1627 SELECT ascii( name ) = ascii( name::text ) AS t FROM srt;
1628 t
1629 ---
1630 t
1631 t
1632 t
1633 t
1634 (4 rows)
1635
1636 SELECT btrim(' trim'::citext ) = 'trim' AS t;
1637 t
1638 ---
1639 t
1640 (1 row)
1641
1642 SELECT btrim('xxxxxtrimxxxx'::citext, 'x'::citext ) = 'trim' AS t;
1643 t
1644 ---
1645 t
1646 (1 row)
1647
1648 SELECT btrim('xyxtrimyyx'::citext, 'xy'::citext) = 'trim' AS t;
1649 t
1650 ---
1651 t
1652 (1 row)
1653
1654 SELECT btrim('xyxtrimyyx'::text, 'xy'::citext) = 'trim' AS t;
1655 t
1656 ---
1657 t
1658 (1 row)
1659
1660 SELECT btrim('xyxtrimyyx'::citext, 'xy'::text ) = 'trim' AS t;
1661 t
1662 ---
1663 t
1664 (1 row)
1665
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;
1669 t
1670 ---
1671 t
1672 t
1673 t
1674 t
1675 (4 rows)
1676
1677 SELECT decode('MTIzAAE='::citext, 'base64') = decode('MTIzAAE='::text, 'base64') AS t;
1678 t
1679 ---
1680 t
1681 (1 row)
1682
1683 -- encode() takes bytea and returns text.
1684 SELECT initcap('hi THOMAS'::citext) = initcap('hi THOMAS'::text) AS t;
1685 t
1686 ---
1687 t
1688 (1 row)
1689
1690 SELECT length( name ) = length( name::text ) AS t FROM srt;
1691 t
1692 ---
1693 t
1694 t
1695 t
1696 t
1697 (4 rows)
1698
1699 SELECT lpad('hi'::citext, 5 ) = ' hi' AS t;
1700 t
1701 ---
1702 t
1703 (1 row)
1704
1705 SELECT lpad('hi'::citext, 5, 'xy'::citext) = 'xyxhi' AS t;
1706 t
1707 ---
1708 t
1709 (1 row)
1710
1711 SELECT lpad('hi'::text, 5, 'xy'::citext) = 'xyxhi' AS t;
1712 t
1713 ---
1714 t
1715 (1 row)
1716
1717 SELECT lpad('hi'::citext, 5, 'xy'::text ) = 'xyxhi' AS t;
1718 t
1719 ---
1720 t
1721 (1 row)
1722
1723 SELECT ltrim(' trim'::citext ) = 'trim' AS t;
1724 t
1725 ---
1726 t
1727 (1 row)
1728
1729 SELECT ltrim('zzzytrim'::citext, 'xyz'::citext) = 'trim' AS t;
1730 t
1731 ---
1732 t
1733 (1 row)
1734
1735 SELECT ltrim('zzzytrim'::text, 'xyz'::citext) = 'trim' AS t;
1736 t
1737 ---
1738 t
1739 (1 row)
1740
1741 SELECT ltrim('zzzytrim'::citext, 'xyz'::text ) = 'trim' AS t;
1742 t
1743 ---
1744 t
1745 (1 row)
1746
1747 -- pg_client_encoding() takes no args and returns name.
1748 SELECT quote_ident( name ) = quote_ident( name::text ) AS t FROM srt;
1749 t
1750 ---
1751 t
1752 t
1753 t
1754 t
1755 (4 rows)
1756
1757 SELECT quote_literal( name ) = quote_literal( name::text ) AS t FROM srt;
1758 t
1759 ---
1760 t
1761 t
1762 t
1763 t
1764 (4 rows)
1765
1766 SELECT regexp_match('foobarbequebaz'::citext, '(bar)(beque)') = ARRAY[ 'bar', 'beque' ] AS t;
1767 t
1768 ---
1769 t
1770 (1 row)
1771
1772 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
1773 t
1774 ---
1775 t
1776 (1 row)
1777
1778 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1779 t
1780 ---
1781 t
1782 (1 row)
1783
1784 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1785 t
1786 ---
1787 t
1788 (1 row)
1789
1790 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
1791 t
1792 ---
1793 t
1794 (1 row)
1795
1796 SELECT regexp_match('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1797 t
1798 ---
1799 t
1800 (1 row)
1801
1802 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1803 t
1804 ---
1805 t
1806 (1 row)
1807
1808 -- c forces case-sensitive
1809 SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no result";
1810 no result
1811 -----------
1812
1813 (1 row)
1814
1815 -- g is not allowed
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;
1821 t
1822 ---
1823 t
1824 (1 row)
1825
1826 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)') = ARRAY[ 'bar', 'beque' ] AS t;
1827 t
1828 ---
1829 t
1830 (1 row)
1831
1832 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1833 t
1834 ---
1835 t
1836 (1 row)
1837
1838 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1839 t
1840 ---
1841 t
1842 (1 row)
1843
1844 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;
1845 t
1846 ---
1847 t
1848 (1 row)
1849
1850 SELECT regexp_matches('foobarbequebaz', '(BAR)(BEQUE)'::citext, '') = ARRAY[ 'bar', 'beque' ] AS t;
1851 t
1852 ---
1853 t
1854 (1 row)
1855
1856 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;
1857 t
1858 ---
1859 t
1860 (1 row)
1861
1862 -- c forces case-sensitive
1863 SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, 'c'::citext) = ARRAY[ 'bar', 'beque' ] AS "no rows";
1864 no rows
1865 ---------
1866 (0 rows)
1867
1868 -- g allows multiple output rows
1869 SELECT regexp_matches('foobarbequebazmorebarbequetoo'::citext, '(BAR)(BEQUE)'::citext, 'g'::citext) AS "two rows";
1870 two rows
1871 -------------
1872 {bar,beque}
1873 {bar,beque}
1874 (2 rows)
1875
1876 SELECT regexp_replace('Thomas'::citext, '.[mN]a.', 'M') = 'ThM' AS t;
1877 t
1878 ---
1879 t
1880 (1 row)
1881
1882 SELECT regexp_replace('Thomas'::citext, '.[MN]A.', 'M') = 'ThM' AS t;
1883 t
1884 ---
1885 t
1886 (1 row)
1887
1888 SELECT regexp_replace('Thomas', '.[MN]A.'::citext, 'M') = 'ThM' AS t;
1889 t
1890 ---
1891 t
1892 (1 row)
1893
1894 SELECT regexp_replace('Thomas'::citext, '.[MN]A.'::citext, 'M') = 'ThM' AS t;
1895 t
1896 ---
1897 t
1898 (1 row)
1899
1900 -- c forces case-sensitive
1901 SELECT regexp_replace('Thomas'::citext, '.[MN]A.'::citext, 'M', 'c') = 'Thomas' AS t;
1902 t
1903 ---
1904 t
1905 (1 row)
1906
1907 SELECT regexp_split_to_array('hello world'::citext, E'\\s+') = ARRAY[ 'hello', 'world' ] AS t;
1908 t
1909 ---
1910 t
1911 (1 row)
1912
1913 SELECT regexp_split_to_array('helloTworld'::citext, 't') = ARRAY[ 'hello', 'world' ] AS t;
1914 t
1915 ---
1916 t
1917 (1 row)
1918
1919 SELECT regexp_split_to_array('helloTworld', 't'::citext) = ARRAY[ 'hello', 'world' ] AS t;
1920 t
1921 ---
1922 t
1923 (1 row)
1924
1925 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext) = ARRAY[ 'hello', 'world' ] AS t;
1926 t
1927 ---
1928 t
1929 (1 row)
1930
1931 SELECT regexp_split_to_array('helloTworld'::citext, 't', 's') = ARRAY[ 'hello', 'world' ] AS t;
1932 t
1933 ---
1934 t
1935 (1 row)
1936
1937 SELECT regexp_split_to_array('helloTworld', 't'::citext, 's') = ARRAY[ 'hello', 'world' ] AS t;
1938 t
1939 ---
1940 t
1941 (1 row)
1942
1943 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext, 's') = ARRAY[ 'hello', 'world' ] AS t;
1944 t
1945 ---
1946 t
1947 (1 row)
1948
1949 -- c forces case-sensitive
1950 SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext, 'c') = ARRAY[ 'helloTworld' ] AS t;
1951 t
1952 ---
1953 t
1954 (1 row)
1955
1956 SELECT regexp_split_to_table('hello world'::citext, E'\\s+') AS words;
1957 words
1958 -------
1959 hello
1960 world
1961 (2 rows)
1962
1963 SELECT regexp_split_to_table('helloTworld'::citext, 't') AS words;
1964 words
1965 -------
1966 hello
1967 world
1968 (2 rows)
1969
1970 SELECT regexp_split_to_table('helloTworld', 't'::citext) AS words;
1971 words
1972 -------
1973 hello
1974 world
1975 (2 rows)
1976
1977 SELECT regexp_split_to_table('helloTworld'::citext, 't'::citext) AS words;
1978 words
1979 -------
1980 hello
1981 world
1982 (2 rows)
1983
1984 -- c forces case-sensitive
1985 SELECT regexp_split_to_table('helloTworld'::citext, 't'::citext, 'c') AS word;
1986 word
1987 -------------
1988 helloTworld
1989 (1 row)
1990
1991 SELECT repeat('Pg'::citext, 4) = 'PgPgPgPg' AS t;
1992 t
1993 ---
1994 t
1995 (1 row)
1996
1997 SELECT replace('abcdefabcdef'::citext, 'cd', 'XX') = 'abXXefabXXef' AS t;
1998 t
1999 ---
2000 t
2001 (1 row)
2002
2003 SELECT replace('abcdefabcdef'::citext, 'CD', 'XX') = 'abXXefabXXef' AS t;
2004 t
2005 ---
2006 t
2007 (1 row)
2008
2009 SELECT replace('ab^is$abcdef'::citext, '^is$', 'XX') = 'abXXabcdef' AS t;
2010 t
2011 ---
2012 t
2013 (1 row)
2014
2015 SELECT replace('abcdefabcdef', 'cd'::citext, 'XX') = 'abXXefabXXef' AS t;
2016 t
2017 ---
2018 t
2019 (1 row)
2020
2021 SELECT replace('abcdefabcdef', 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
2022 t
2023 ---
2024 t
2025 (1 row)
2026
2027 SELECT replace('ab^is$abcdef', '^is$'::citext, 'XX') = 'abXXabcdef' AS t;
2028 t
2029 ---
2030 t
2031 (1 row)
2032
2033 SELECT replace('abcdefabcdef'::citext, 'cd'::citext, 'XX') = 'abXXefabXXef' AS t;
2034 t
2035 ---
2036 t
2037 (1 row)
2038
2039 SELECT replace('abcdefabcdef'::citext, 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
2040 t
2041 ---
2042 t
2043 (1 row)
2044
2045 SELECT replace('ab^is$abcdef'::citext, '^is$'::citext, 'XX') = 'abXXabcdef' AS t;
2046 t
2047 ---
2048 t
2049 (1 row)
2050
2051 SELECT rpad('hi'::citext, 5 ) = 'hi ' AS t;
2052 t
2053 ---
2054 t
2055 (1 row)
2056
2057 SELECT rpad('hi'::citext, 5, 'xy'::citext) = 'hixyx' AS t;
2058 t
2059 ---
2060 t
2061 (1 row)
2062
2063 SELECT rpad('hi'::text, 5, 'xy'::citext) = 'hixyx' AS t;
2064 t
2065 ---
2066 t
2067 (1 row)
2068
2069 SELECT rpad('hi'::citext, 5, 'xy'::text ) = 'hixyx' AS t;
2070 t
2071 ---
2072 t
2073 (1 row)
2074
2075 SELECT rtrim('trim '::citext ) = 'trim' AS t;
2076 t
2077 ---
2078 t
2079 (1 row)
2080
2081 SELECT rtrim('trimxxxx'::citext, 'x'::citext) = 'trim' AS t;
2082 t
2083 ---
2084 t
2085 (1 row)
2086
2087 SELECT rtrim('trimxxxx'::text, 'x'::citext) = 'trim' AS t;
2088 t
2089 ---
2090 t
2091 (1 row)
2092
2093 SELECT rtrim('trimxxxx'::text, 'x'::text ) = 'trim' AS t;
2094 t
2095 ---
2096 t
2097 (1 row)
2098
2099 SELECT split_part('abc~@~def~@~ghi'::citext, '~@~', 2) = 'def' AS t;
2100 t
2101 ---
2102 t
2103 (1 row)
2104
2105 SELECT split_part('abcTdefTghi'::citext, 't', 2) = 'def' AS t;
2106 t
2107 ---
2108 t
2109 (1 row)
2110
2111 SELECT split_part('abcTdefTghi'::citext, 't'::citext, 2) = 'def' AS t;
2112 t
2113 ---
2114 t
2115 (1 row)
2116
2117 SELECT split_part('abcTdefTghi', 't'::citext, 2) = 'def' AS t;
2118 t
2119 ---
2120 t
2121 (1 row)
2122
2123 SELECT strpos('high'::citext, 'gh' ) = 3 AS t;
2124 t
2125 ---
2126 t
2127 (1 row)
2128
2129 SELECT strpos('high', 'gh'::citext) = 3 AS t;
2130 t
2131 ---
2132 t
2133 (1 row)
2134
2135 SELECT strpos('high'::citext, 'gh'::citext) = 3 AS t;
2136 t
2137 ---
2138 t
2139 (1 row)
2140
2141 SELECT strpos('high'::citext, 'GH' ) = 3 AS t;
2142 t
2143 ---
2144 t
2145 (1 row)
2146
2147 SELECT strpos('high', 'GH'::citext) = 3 AS t;
2148 t
2149 ---
2150 t
2151 (1 row)
2152
2153 SELECT strpos('high'::citext, 'GH'::citext) = 3 AS t;
2154 t
2155 ---
2156 t
2157 (1 row)
2158
2159 -- to_ascii() does not support UTF-8.
2160 -- to_hex() takes a numeric argument.
2161 SELECT substr('alphabet', 3, 2) = 'ph' AS t;
2162 t
2163 ---
2164 t
2165 (1 row)
2166
2167 SELECT translate('abcdefabcdef'::citext, 'cd', 'XX') = 'abXXefabXXef' AS t;
2168 t
2169 ---
2170 t
2171 (1 row)
2172
2173 SELECT translate('abcdefabcdef'::citext, 'CD', 'XX') = 'abXXefabXXef' AS t;
2174 t
2175 ---
2176 t
2177 (1 row)
2178
2179 SELECT translate('abcdefabcdef'::citext, 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
2180 t
2181 ---
2182 t
2183 (1 row)
2184
2185 SELECT translate('abcdefabcdef', 'CD'::citext, 'XX') = 'abXXefabXXef' AS t;
2186 t
2187 ---
2188 t
2189 (1 row)
2190
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;
2194 t
2195 ---
2196 t
2197 (1 row)
2198
2199 SELECT to_date('05 Dec 2000'::citext, 'DD Mon YYYY')
2200 = to_date('05 Dec 2000', 'DD Mon YYYY') AS t;
2201 t
2202 ---
2203 t
2204 (1 row)
2205
2206 SELECT to_date('05 Dec 2000', 'DD Mon YYYY'::citext)
2207 = to_date('05 Dec 2000', 'DD Mon YYYY') AS t;
2208 t
2209 ---
2210 t
2211 (1 row)
2212
2213 SELECT to_number('12,454.8-'::citext, '99G999D9S'::citext)
2214 = to_number('12,454.8-', '99G999D9S') AS t;
2215 t
2216 ---
2217 t
2218 (1 row)
2219
2220 SELECT to_number('12,454.8-'::citext, '99G999D9S')
2221 = to_number('12,454.8-', '99G999D9S') AS t;
2222 t
2223 ---
2224 t
2225 (1 row)
2226
2227 SELECT to_number('12,454.8-', '99G999D9S'::citext)
2228 = to_number('12,454.8-', '99G999D9S') AS t;
2229 t
2230 ---
2231 t
2232 (1 row)
2233
2234 SELECT to_timestamp('05 Dec 2000'::citext, 'DD Mon YYYY'::citext)
2235 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
2236 t
2237 ---
2238 t
2239 (1 row)
2240
2241 SELECT to_timestamp('05 Dec 2000'::citext, 'DD Mon YYYY')
2242 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
2243 t
2244 ---
2245 t
2246 (1 row)
2247
2248 SELECT to_timestamp('05 Dec 2000', 'DD Mon YYYY'::citext)
2249 = to_timestamp('05 Dec 2000', 'DD Mon YYYY') AS t;
2250 t
2251 ---
2252 t
2253 (1 row)
2254
2255 -- Try assigning function results to a column.
2256 SELECT COUNT(*) = 8::bigint AS t FROM try;
2257 t
2258 ---
2259 t
2260 (1 row)
2261
2262 INSERT INTO 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;
2275 t
2276 ---
2277 t
2278 (1 row)
2279
2280 SELECT like_escape( name, '' ) = like_escape( name::text, '' ) AS t FROM srt;
2281 t
2282 ---
2283 t
2284 t
2285 t
2286 t
2287 (4 rows)
2288
2289 SELECT like_escape( name::text, ''::citext ) = like_escape( name::text, '' ) AS t FROM srt;
2290 t
2291 ---
2292 t
2293 t
2294 t
2295 t
2296 (4 rows)
2297
2298 -- Ensure correct behavior for citext with materialized views.
2299 CREATE TABLE citext_table (
2300 id serial primary key,
2301 name citext
2302 );
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);
2309 SELECT *
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 ----+------+----+------
2315 (0 rows)
2316
2317 UPDATE citext_table SET name = 'Two' WHERE name = 'TWO';
2318 SELECT *
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 ----+------+----+------
2324 | | 2 | Two
2325 2 | two | |
2326 (2 rows)
2327
2328 REFRESH MATERIALIZED VIEW CONCURRENTLY citext_matview;
2329 SELECT * FROM citext_matview ORDER BY id;
2330 id | name
2331 ----+-------
2332 1 | one
2333 2 | Two
2334 3 | three
2335 4 |
2336 5 |
2337 (5 rows)
2338
2339 -- test citext_pattern_cmp() function explicitly.
2340 SELECT citext_pattern_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
2341 zero
2342 ------
2343 0
2344 (1 row)
2345
2346 SELECT citext_pattern_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
2347 zero
2348 ------
2349 0
2350 (1 row)
2351
2352 SELECT citext_pattern_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
2353 zero
2354 ------
2355 0
2356 (1 row)
2357
2358 SELECT citext_pattern_cmp('B'::citext, 'a'::citext) > 0 AS true;
2359 true
2360 ------
2361 t
2362 (1 row)
2363
2364 SELECT citext_pattern_cmp('a'::citext, 'B'::citext) < 0 AS true;
2365 true
2366 ------
2367 t
2368 (1 row)
2369
2370 SELECT citext_pattern_cmp('A'::citext, 'b'::citext) < 0 AS true;
2371 true
2372 ------
2373 t
2374 (1 row)
2375
2376 SELECT citext_pattern_cmp('ABCD'::citext, 'abc'::citext) > 0 AS true;
2377 true
2378 ------
2379 t
2380 (1 row)
2381
2382 SELECT citext_pattern_cmp('ABC'::citext, 'abcd'::citext) < 0 AS true;
2383 true
2384 ------
2385 t
2386 (1 row)
2387
2388 -- test operator functions
2389 -- lt
2390 SELECT citext_pattern_lt('a'::citext, 'b'::citext) AS true;
2391 true
2392 ------
2393 t
2394 (1 row)
2395
2396 SELECT citext_pattern_lt('A'::citext, 'b'::citext) AS true;
2397 true
2398 ------
2399 t
2400 (1 row)
2401
2402 SELECT citext_pattern_lt('a'::citext, 'B'::citext) AS true;
2403 true
2404 ------
2405 t
2406 (1 row)
2407
2408 SELECT citext_pattern_lt('b'::citext, 'a'::citext) AS false;
2409 false
2410 -------
2411 f
2412 (1 row)
2413
2414 SELECT citext_pattern_lt('B'::citext, 'a'::citext) AS false;
2415 false
2416 -------
2417 f
2418 (1 row)
2419
2420 SELECT citext_pattern_lt('b'::citext, 'A'::citext) AS false;
2421 false
2422 -------
2423 f
2424 (1 row)
2425
2426 -- le
2427 SELECT citext_pattern_le('a'::citext, 'a'::citext) AS true;
2428 true
2429 ------
2430 t
2431 (1 row)
2432
2433 SELECT citext_pattern_le('a'::citext, 'A'::citext) AS true;
2434 true
2435 ------
2436 t
2437 (1 row)
2438
2439 SELECT citext_pattern_le('A'::citext, 'a'::citext) AS true;
2440 true
2441 ------
2442 t
2443 (1 row)
2444
2445 SELECT citext_pattern_le('A'::citext, 'A'::citext) AS true;
2446 true
2447 ------
2448 t
2449 (1 row)
2450
2451 SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
2452 true
2453 ------
2454 t
2455 (1 row)
2456
2457 SELECT citext_pattern_le('A'::citext, 'b'::citext) AS true;
2458 true
2459 ------
2460 t
2461 (1 row)
2462
2463 SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
2464 true
2465 ------
2466 t
2467 (1 row)
2468
2469 SELECT citext_pattern_le('b'::citext, 'a'::citext) AS false;
2470 false
2471 -------
2472 f
2473 (1 row)
2474
2475 SELECT citext_pattern_le('B'::citext, 'a'::citext) AS false;
2476 false
2477 -------
2478 f
2479 (1 row)
2480
2481 SELECT citext_pattern_le('b'::citext, 'A'::citext) AS false;
2482 false
2483 -------
2484 f
2485 (1 row)
2486
2487 -- gt
2488 SELECT citext_pattern_gt('a'::citext, 'b'::citext) AS false;
2489 false
2490 -------
2491 f
2492 (1 row)
2493
2494 SELECT citext_pattern_gt('A'::citext, 'b'::citext) AS false;
2495 false
2496 -------
2497 f
2498 (1 row)
2499
2500 SELECT citext_pattern_gt('a'::citext, 'B'::citext) AS false;
2501 false
2502 -------
2503 f
2504 (1 row)
2505
2506 SELECT citext_pattern_gt('b'::citext, 'a'::citext) AS true;
2507 true
2508 ------
2509 t
2510 (1 row)
2511
2512 SELECT citext_pattern_gt('B'::citext, 'a'::citext) AS true;
2513 true
2514 ------
2515 t
2516 (1 row)
2517
2518 SELECT citext_pattern_gt('b'::citext, 'A'::citext) AS true;
2519 true
2520 ------
2521 t
2522 (1 row)
2523
2524 -- ge
2525 SELECT citext_pattern_ge('a'::citext, 'a'::citext) AS true;
2526 true
2527 ------
2528 t
2529 (1 row)
2530
2531 SELECT citext_pattern_ge('a'::citext, 'A'::citext) AS true;
2532 true
2533 ------
2534 t
2535 (1 row)
2536
2537 SELECT citext_pattern_ge('A'::citext, 'a'::citext) AS true;
2538 true
2539 ------
2540 t
2541 (1 row)
2542
2543 SELECT citext_pattern_ge('A'::citext, 'A'::citext) AS true;
2544 true
2545 ------
2546 t
2547 (1 row)
2548
2549 SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
2550 false
2551 -------
2552 f
2553 (1 row)
2554
2555 SELECT citext_pattern_ge('A'::citext, 'b'::citext) AS false;
2556 false
2557 -------
2558 f
2559 (1 row)
2560
2561 SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
2562 false
2563 -------
2564 f
2565 (1 row)
2566
2567 SELECT citext_pattern_ge('b'::citext, 'a'::citext) AS true;
2568 true
2569 ------
2570 t
2571 (1 row)
2572
2573 SELECT citext_pattern_ge('B'::citext, 'a'::citext) AS true;
2574 true
2575 ------
2576 t
2577 (1 row)
2578
2579 SELECT citext_pattern_ge('b'::citext, 'A'::citext) AS true;
2580 true
2581 ------
2582 t
2583 (1 row)
2584
2585 -- Test ~<~ and ~<=~
2586 SELECT 'a'::citext ~<~ 'B'::citext AS t;
2587 t
2588 ---
2589 t
2590 (1 row)
2591
2592 SELECT 'b'::citext ~<~ 'A'::citext AS f;
2593 f
2594 ---
2595 f
2596 (1 row)
2597
2598 SELECT 'a'::citext ~<=~ 'B'::citext AS t;
2599 t
2600 ---
2601 t
2602 (1 row)
2603
2604 SELECT 'a'::citext ~<=~ 'A'::citext AS t;
2605 t
2606 ---
2607 t
2608 (1 row)
2609
2610 -- Test ~>~ and ~>=~
2611 SELECT 'B'::citext ~>~ 'a'::citext AS t;
2612 t
2613 ---
2614 t
2615 (1 row)
2616
2617 SELECT 'b'::citext ~>~ 'A'::citext AS t;
2618 t
2619 ---
2620 t
2621 (1 row)
2622
2623 SELECT 'B'::citext ~>~ 'b'::citext AS f;
2624 f
2625 ---
2626 f
2627 (1 row)
2628
2629 SELECT 'B'::citext ~>=~ 'b'::citext AS t;
2630 t
2631 ---
2632 t
2633 (1 row)
2634
2635 -- Test implicit casting. citext casts to text, but not vice-versa.
2636 SELECT 'B'::citext ~<~ 'a'::text AS t; -- text wins.
2637 t
2638 ---
2639 t
2640 (1 row)
2641
2642 SELECT 'B'::citext ~<=~ 'a'::text AS t; -- text wins.
2643 t
2644 ---
2645 t
2646 (1 row)
2647
2648 SELECT 'a'::citext ~>~ 'B'::text AS t; -- text wins.
2649 t
2650 ---
2651 t
2652 (1 row)
2653
2654 SELECT 'a'::citext ~>=~ 'B'::text AS t; -- text wins.
2655 t
2656 ---
2657 t
2658 (1 row)
2659
2660 -- Test implicit casting. citext casts to varchar, but not vice-versa.
2661 SELECT 'B'::citext ~<~ 'a'::varchar AS t; -- varchar wins.
2662 t
2663 ---
2664 t
2665 (1 row)
2666
2667 SELECT 'B'::citext ~<=~ 'a'::varchar AS t; -- varchar wins.
2668 t
2669 ---
2670 t
2671 (1 row)
2672
2673 SELECT 'a'::citext ~>~ 'B'::varchar AS t; -- varchar wins.
2674 t
2675 ---
2676 t
2677 (1 row)
2678
2679 SELECT 'a'::citext ~>=~ 'B'::varchar AS t; -- varchar wins.
2680 t
2681 ---
2682 t
2683 (1 row)
2684