Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / src / test / regress / expected / strings.out
blob1241a2ace63a04ecfbb8408e9b4175f183b6cad1
1 --
2 -- STRINGS
3 -- Test various data entry syntaxes.
4 --
5 -- SQL92 string continuation syntax
6 -- E021-03 character string literals
7 SELECT 'first line'
8 ' - next line'
9         ' - third line'
10         AS "Three lines to one";
11          Three lines to one          
12 -------------------------------------
13  first line - next line - third line
14 (1 row)
16 -- illegal string continuation syntax
17 SELECT 'first line'
18 ' - next line' /* this comment is not allowed here */
19 ' - third line'
20         AS "Illegal comment within continuation";
21 ERROR:  syntax error at or near "' - third line'"
22 LINE 3: ' - third line'
23         ^
24 -- Unicode escapes
25 SET standard_conforming_strings TO on;
26 SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
27  data 
28 ------
29  data
30 (1 row)
32 SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
33  dat\+000061 
34 -------------
35  dat\+000061
36 (1 row)
38 SELECT U&' \' UESCAPE '!' AS "tricky";
39  tricky 
40 --------
41   \
42 (1 row)
44 SELECT 'tricky' AS U&"\" UESCAPE '!';
45    \    
46 --------
47  tricky
48 (1 row)
50 SELECT U&'wrong: \061';
51 ERROR:  invalid Unicode escape value at or near "\061'"
52 LINE 1: SELECT U&'wrong: \061';
53                          ^
54 SELECT U&'wrong: \+0061';
55 ERROR:  invalid Unicode escape value at or near "\+0061'"
56 LINE 1: SELECT U&'wrong: \+0061';
57                          ^
58 SELECT U&'wrong: +0061' UESCAPE '+';
59 ERROR:  invalid Unicode escape character at or near "+'"
60 LINE 1: SELECT U&'wrong: +0061' UESCAPE '+';
61                                          ^
62 SET standard_conforming_strings TO off;
63 SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
64 ERROR:  unsafe use of string constant with Unicode escapes
65 LINE 1: SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
66                ^
67 DETAIL:  String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
68 SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
69 ERROR:  unsafe use of string constant with Unicode escapes
70 LINE 1: SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061...
71                ^
72 DETAIL:  String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
73 SELECT U&' \' UESCAPE '!' AS "tricky";
74 ERROR:  unsafe use of string constant with Unicode escapes
75 LINE 1: SELECT U&' \' UESCAPE '!' AS "tricky";
76                ^
77 DETAIL:  String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
78 SELECT 'tricky' AS U&"\" UESCAPE '!';
79    \    
80 --------
81  tricky
82 (1 row)
84 SELECT U&'wrong: \061';
85 ERROR:  unsafe use of string constant with Unicode escapes
86 LINE 1: SELECT U&'wrong: \061';
87                ^
88 DETAIL:  String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
89 SELECT U&'wrong: \+0061';
90 ERROR:  unsafe use of string constant with Unicode escapes
91 LINE 1: SELECT U&'wrong: \+0061';
92                ^
93 DETAIL:  String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
94 SELECT U&'wrong: +0061' UESCAPE '+';
95 ERROR:  unsafe use of string constant with Unicode escapes
96 LINE 1: SELECT U&'wrong: +0061' UESCAPE '+';
97                ^
98 DETAIL:  String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
99 RESET standard_conforming_strings;
101 -- test conversions between various string types
102 -- E021-10 implicit casting among the character data types
104 SELECT CAST(f1 AS text) AS "text(char)" FROM CHAR_TBL;
105  text(char) 
106 ------------
108  ab
109  abcd
110  abcd
111 (4 rows)
113 SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL;
114  text(varchar) 
115 ---------------
117  ab
118  abcd
119  abcd
120 (4 rows)
122 SELECT CAST(name 'namefield' AS text) AS "text(name)";
123  text(name) 
124 ------------
125  namefield
126 (1 row)
128 -- since this is an explicit cast, it should truncate w/o error:
129 SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL;
130  char(text) 
131 ------------
132  doh!      
133  hi de ho n
134 (2 rows)
136 -- note: implicit-cast case is tested in char.sql
137 SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL;
138       char(text)      
139 ----------------------
140  doh!                
141  hi de ho neighbor   
142 (2 rows)
144 SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL;
145  char(varchar) 
146 ---------------
147  a         
148  ab        
149  abcd      
150  abcd      
151 (4 rows)
153 SELECT CAST(name 'namefield' AS char(10)) AS "char(name)";
154  char(name) 
155 ------------
156  namefield 
157 (1 row)
159 SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL;
160    varchar(text)   
161 -------------------
162  doh!
163  hi de ho neighbor
164 (2 rows)
166 SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL;
167  varchar(char) 
168 ---------------
170  ab
171  abcd
172  abcd
173 (4 rows)
175 SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)";
176  varchar(name) 
177 ---------------
178  namefield
179 (1 row)
182 -- test SQL92 string functions
183 -- E### and T### are feature reference numbers from SQL99
185 -- E021-09 trim function
186 SELECT TRIM(BOTH FROM '  bunch o blanks  ') = 'bunch o blanks' AS "bunch o blanks";
187  bunch o blanks 
188 ----------------
190 (1 row)
192 SELECT TRIM(LEADING FROM '  bunch o blanks  ') = 'bunch o blanks  ' AS "bunch o blanks  ";
193  bunch o blanks   
194 ------------------
196 (1 row)
198 SELECT TRIM(TRAILING FROM '  bunch o blanks  ') = '  bunch o blanks' AS "  bunch o blanks";
199    bunch o blanks 
200 ------------------
202 (1 row)
204 SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs";
205  some Xs 
206 ---------
208 (1 row)
210 -- E021-06 substring expression
211 SELECT SUBSTRING('1234567890' FROM 3) = '34567890' AS "34567890";
212  34567890 
213 ----------
215 (1 row)
217 SELECT SUBSTRING('1234567890' FROM 4 FOR 3) = '456' AS "456";
218  456 
219 -----
221 (1 row)
223 -- T581 regular expression substring (with SQL99's bizarre regexp syntax)
224 SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd";
225  bcd 
226 -----
227  bcd
228 (1 row)
230 -- No match should return NULL
231 SELECT SUBSTRING('abcdefg' FROM '#"(b_d)#"%' FOR '#') IS NULL AS "True";
232  True 
233 ------
235 (1 row)
237 -- Null inputs should return NULL
238 SELECT SUBSTRING('abcdefg' FROM '(b|c)' FOR NULL) IS NULL AS "True";
239  True 
240 ------
242 (1 row)
244 SELECT SUBSTRING(NULL FROM '(b|c)' FOR '#') IS NULL AS "True";
245  True 
246 ------
248 (1 row)
250 SELECT SUBSTRING('abcdefg' FROM NULL FOR '#') IS NULL AS "True";
251  True 
252 ------
254 (1 row)
256 -- PostgreSQL extension to allow omitting the escape character;
257 -- here the regexp is taken as Posix syntax
258 SELECT SUBSTRING('abcdefg' FROM 'c.e') AS "cde";
259  cde 
260 -----
261  cde
262 (1 row)
264 -- With a parenthesized subexpression, return only what matches the subexpr
265 SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde";
266  cde 
267 -----
268  cde
269 (1 row)
271 -- PostgreSQL extension to allow using back reference in replace string;
272 SELECT regexp_replace('1112223333', E'(\\d{3})(\\d{3})(\\d{4})', E'(\\1) \\2-\\3');
273  regexp_replace 
274 ----------------
275  (111) 222-3333
276 (1 row)
278 SELECT regexp_replace('AAA   BBB   CCC   ', E'\\s+', ' ', 'g');
279  regexp_replace 
280 ----------------
281  AAA BBB CCC 
282 (1 row)
284 SELECT regexp_replace('AAA', '^|$', 'Z', 'g');
285  regexp_replace 
286 ----------------
287  ZAAAZ
288 (1 row)
290 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi');
291  regexp_replace 
292 ----------------
293  Z Z
294 (1 row)
296 -- invalid regexp option
297 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'z');
298 ERROR:  invalid regexp option: "z"
299 -- set so we can tell NULL from empty string
300 \pset null '\\N'
301 -- return all matches from regexp
302 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$);
303  regexp_matches 
304 ----------------
305  {bar,beque}
306 (1 row)
308 -- test case insensitive
309 SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i');
310  regexp_matches 
311 ----------------
312  {bAR,bEqUE}
313 (1 row)
315 -- global option - more than one match
316 SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g');
317  regexp_matches 
318 ----------------
319  {bar,beque}
320  {bazil,barf}
321 (2 rows)
323 -- empty capture group (matched empty string)
324 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$);
325  regexp_matches 
326 ----------------
327  {bar,"",beque}
328 (1 row)
330 -- no match
331 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$);
332  regexp_matches 
333 ----------------
334 (0 rows)
336 -- optional capture group did not match, null entry in array
337 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$);
338   regexp_matches  
339 ------------------
340  {bar,NULL,beque}
341 (1 row)
343 -- no capture groups
344 SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$);
345  regexp_matches 
346 ----------------
347  {barbeque}
348 (1 row)
350 -- give me errors
351 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$, 'gz');
352 ERROR:  invalid regexp option: "z"
353 SELECT regexp_matches('foobarbequebaz', $re$(barbeque$re$);
354 ERROR:  invalid regular expression: parentheses () not balanced
355 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque){2,1}$re$);
356 ERROR:  invalid regular expression: invalid repetition count(s)
357 -- split string on regexp
358 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', $re$\s+$re$) AS foo;
359   foo   | length 
360 --------+--------
361  the    |      3
362  quick  |      5
363  brown  |      5
364  fox    |      3
365  jumped |      6
366  over   |      4
367  the    |      3
368  lazy   |      4
369  dog    |      3
370 (9 rows)
372 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', $re$\s+$re$);
373              regexp_split_to_array              
374 ------------------------------------------------
375  {the,quick,brown,fox,jumped,over,the,lazy,dog}
376 (1 row)
378 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', $re$\s*$re$) AS foo;
379  foo | length 
380 -----+--------
381  t   |      1
382  h   |      1
383  e   |      1
384  q   |      1
385  u   |      1
386  i   |      1
387  c   |      1
388  k   |      1
389  b   |      1
390  r   |      1
391  o   |      1
392  w   |      1
393  n   |      1
394  f   |      1
395  o   |      1
396  x   |      1
397  j   |      1
398  u   |      1
399  m   |      1
400  p   |      1
401  e   |      1
402  d   |      1
403  o   |      1
404  v   |      1
405  e   |      1
406  r   |      1
407  t   |      1
408  h   |      1
409  e   |      1
410  l   |      1
411  a   |      1
412  z   |      1
413  y   |      1
414  d   |      1
415  o   |      1
416  g   |      1
417 (36 rows)
419 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', $re$\s*$re$);
420                            regexp_split_to_array                           
421 ---------------------------------------------------------------------------
422  {t,h,e,q,u,i,c,k,b,r,o,w,n,f,o,x,j,u,m,p,e,d,o,v,e,r,t,h,e,l,a,z,y,d,o,g}
423 (1 row)
425 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', '') AS foo;
426  foo | length 
427 -----+--------
428  t   |      1
429  h   |      1
430  e   |      1
431      |      1
432  q   |      1
433  u   |      1
434  i   |      1
435  c   |      1
436  k   |      1
437      |      1
438  b   |      1
439  r   |      1
440  o   |      1
441  w   |      1
442  n   |      1
443      |      1
444  f   |      1
445  o   |      1
446  x   |      1
447      |      1
448  j   |      1
449  u   |      1
450  m   |      1
451  p   |      1
452  e   |      1
453  d   |      1
454      |      1
455  o   |      1
456  v   |      1
457  e   |      1
458  r   |      1
459      |      1
460  t   |      1
461  h   |      1
462  e   |      1
463      |      1
464  l   |      1
465  a   |      1
466  z   |      1
467  y   |      1
468      |      1
469  d   |      1
470  o   |      1
471  g   |      1
472 (44 rows)
474 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', '');
475                                            regexp_split_to_array                                           
476 -----------------------------------------------------------------------------------------------------------
477  {t,h,e," ",q,u,i,c,k," ",b,r,o,w,n," ",f,o,x," ",j,u,m,p,e,d," ",o,v,e,r," ",t,h,e," ",l,a,z,y," ",d,o,g}
478 (1 row)
480 -- case insensitive
481 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'i') AS foo;
482           foo          | length 
483 -----------------------+--------
484  th                    |      2
485   QUick bROWn FOx jUMP |     21
486  d ov                  |      4
487  r TH                  |      4
488   lazy dOG             |      9
489 (5 rows)
491 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'i');
492                  regexp_split_to_array                  
493 --------------------------------------------------------
494  {th," QUick bROWn FOx jUMP","d ov","r TH"," lazy dOG"}
495 (1 row)
497 -- no match of pattern
498 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', 'nomatch') AS foo;
499                      foo                      | length 
500 ----------------------------------------------+--------
501  the quick brown fox jumped over the lazy dog |     44
502 (1 row)
504 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', 'nomatch');
505               regexp_split_to_array               
506 --------------------------------------------------
507  {"the quick brown fox jumped over the lazy dog"}
508 (1 row)
510 -- some corner cases
511 SELECT regexp_split_to_array('123456','1');
512  regexp_split_to_array 
513 -----------------------
514  {"",23456}
515 (1 row)
517 SELECT regexp_split_to_array('123456','6');
518  regexp_split_to_array 
519 -----------------------
520  {12345,""}
521 (1 row)
523 SELECT regexp_split_to_array('123456','.');
524  regexp_split_to_array  
525 ------------------------
526  {"","","","","","",""}
527 (1 row)
529 -- errors
530 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'zippy') AS foo;
531 ERROR:  invalid regexp option: "z"
532 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'iz');
533 ERROR:  invalid regexp option: "z"
534 -- global option meaningless for regexp_split
535 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'g') AS foo;
536 ERROR:  regexp_split does not support the global option
537 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'g');
538 ERROR:  regexp_split does not support the global option
539 -- change NULL-display back
540 \pset null ''
541 -- E021-11 position expression
542 SELECT POSITION('4' IN '1234567890') = '4' AS "4";
543  4 
546 (1 row)
548 SELECT POSITION('5' IN '1234567890') = '5' AS "5";
549  5 
552 (1 row)
554 -- T312 character overlay function
555 SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
556  abc45f 
557 --------
558  abc45f
559 (1 row)
561 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5) AS "yabadaba";
562  yabadaba 
563 ----------
564  yabadaba
565 (1 row)
567 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5 FOR 0) AS "yabadabadoo";
568  yabadabadoo 
569 -------------
570  yabadabadoo
571 (1 row)
573 SELECT OVERLAY('babosa' PLACING 'ubb' FROM 2 FOR 4) AS "bubba";
574  bubba 
575 -------
576  bubba
577 (1 row)
580 -- test LIKE
581 -- Be sure to form every test as a LIKE/NOT LIKE pair.
583 -- simplest examples
584 -- E061-04 like predicate
585 SELECT 'hawkeye' LIKE 'h%' AS "true";
586  true 
587 ------
589 (1 row)
591 SELECT 'hawkeye' NOT LIKE 'h%' AS "false";
592  false 
593 -------
595 (1 row)
597 SELECT 'hawkeye' LIKE 'H%' AS "false";
598  false 
599 -------
601 (1 row)
603 SELECT 'hawkeye' NOT LIKE 'H%' AS "true";
604  true 
605 ------
607 (1 row)
609 SELECT 'hawkeye' LIKE 'indio%' AS "false";
610  false 
611 -------
613 (1 row)
615 SELECT 'hawkeye' NOT LIKE 'indio%' AS "true";
616  true 
617 ------
619 (1 row)
621 SELECT 'hawkeye' LIKE 'h%eye' AS "true";
622  true 
623 ------
625 (1 row)
627 SELECT 'hawkeye' NOT LIKE 'h%eye' AS "false";
628  false 
629 -------
631 (1 row)
633 SELECT 'indio' LIKE '_ndio' AS "true";
634  true 
635 ------
637 (1 row)
639 SELECT 'indio' NOT LIKE '_ndio' AS "false";
640  false 
641 -------
643 (1 row)
645 SELECT 'indio' LIKE 'in__o' AS "true";
646  true 
647 ------
649 (1 row)
651 SELECT 'indio' NOT LIKE 'in__o' AS "false";
652  false 
653 -------
655 (1 row)
657 SELECT 'indio' LIKE 'in_o' AS "false";
658  false 
659 -------
661 (1 row)
663 SELECT 'indio' NOT LIKE 'in_o' AS "true";
664  true 
665 ------
667 (1 row)
669 -- unused escape character
670 SELECT 'hawkeye' LIKE 'h%' ESCAPE '#' AS "true";
671  true 
672 ------
674 (1 row)
676 SELECT 'hawkeye' NOT LIKE 'h%' ESCAPE '#' AS "false";
677  false 
678 -------
680 (1 row)
682 SELECT 'indio' LIKE 'ind_o' ESCAPE '$' AS "true";
683  true 
684 ------
686 (1 row)
688 SELECT 'indio' NOT LIKE 'ind_o' ESCAPE '$' AS "false";
689  false 
690 -------
692 (1 row)
694 -- escape character
695 -- E061-05 like predicate with escape clause
696 SELECT 'h%' LIKE 'h#%' ESCAPE '#' AS "true";
697  true 
698 ------
700 (1 row)
702 SELECT 'h%' NOT LIKE 'h#%' ESCAPE '#' AS "false";
703  false 
704 -------
706 (1 row)
708 SELECT 'h%wkeye' LIKE 'h#%' ESCAPE '#' AS "false";
709  false 
710 -------
712 (1 row)
714 SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true";
715  true 
716 ------
718 (1 row)
720 SELECT 'h%wkeye' LIKE 'h#%%' ESCAPE '#' AS "true";
721  true 
722 ------
724 (1 row)
726 SELECT 'h%wkeye' NOT LIKE 'h#%%' ESCAPE '#' AS "false";
727  false 
728 -------
730 (1 row)
732 SELECT 'h%awkeye' LIKE 'h#%a%k%e' ESCAPE '#' AS "true";
733  true 
734 ------
736 (1 row)
738 SELECT 'h%awkeye' NOT LIKE 'h#%a%k%e' ESCAPE '#' AS "false";
739  false 
740 -------
742 (1 row)
744 SELECT 'indio' LIKE '_ndio' ESCAPE '$' AS "true";
745  true 
746 ------
748 (1 row)
750 SELECT 'indio' NOT LIKE '_ndio' ESCAPE '$' AS "false";
751  false 
752 -------
754 (1 row)
756 SELECT 'i_dio' LIKE 'i$_d_o' ESCAPE '$' AS "true";
757  true 
758 ------
760 (1 row)
762 SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false";
763  false 
764 -------
766 (1 row)
768 SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false";
769  false 
770 -------
772 (1 row)
774 SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true";
775  true 
776 ------
778 (1 row)
780 SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true";
781  true 
782 ------
784 (1 row)
786 SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false";
787  false 
788 -------
790 (1 row)
792 -- escape character same as pattern character
793 SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true";
794  true 
795 ------
797 (1 row)
799 SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false";
800  false 
801 -------
803 (1 row)
805 SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true";
806  true 
807 ------
809 (1 row)
811 SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false";
812  false 
813 -------
815 (1 row)
817 SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true";
818  true 
819 ------
821 (1 row)
823 SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false";
824  false 
825 -------
827 (1 row)
829 SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true";
830  true 
831 ------
833 (1 row)
835 SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false";
836  false 
837 -------
839 (1 row)
841 SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false";
842  false 
843 -------
845 (1 row)
847 SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true";
848  true 
849 ------
851 (1 row)
854 -- test ILIKE (case-insensitive LIKE)
855 -- Be sure to form every test as an ILIKE/NOT ILIKE pair.
857 SELECT 'hawkeye' ILIKE 'h%' AS "true";
858  true 
859 ------
861 (1 row)
863 SELECT 'hawkeye' NOT ILIKE 'h%' AS "false";
864  false 
865 -------
867 (1 row)
869 SELECT 'hawkeye' ILIKE 'H%' AS "true";
870  true 
871 ------
873 (1 row)
875 SELECT 'hawkeye' NOT ILIKE 'H%' AS "false";
876  false 
877 -------
879 (1 row)
881 SELECT 'hawkeye' ILIKE 'H%Eye' AS "true";
882  true 
883 ------
885 (1 row)
887 SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false";
888  false 
889 -------
891 (1 row)
893 SELECT 'Hawkeye' ILIKE 'h%' AS "true";
894  true 
895 ------
897 (1 row)
899 SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false";
900  false 
901 -------
903 (1 row)
906 -- test %/_ combination cases, cf bug #4821
908 SELECT 'foo' LIKE '_%' as t, 'f' LIKE '_%' as t, '' LIKE '_%' as f;
909  t | t | f 
910 ---+---+---
911  t | t | f
912 (1 row)
914 SELECT 'foo' LIKE '%_' as t, 'f' LIKE '%_' as t, '' LIKE '%_' as f;
915  t | t | f 
916 ---+---+---
917  t | t | f
918 (1 row)
920 SELECT 'foo' LIKE '__%' as t, 'foo' LIKE '___%' as t, 'foo' LIKE '____%' as f;
921  t | t | f 
922 ---+---+---
923  t | t | f
924 (1 row)
926 SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f;
927  t | t | f 
928 ---+---+---
929  t | t | f
930 (1 row)
933 -- test implicit type conversion
935 -- E021-07 character concatenation
936 SELECT 'unknown' || ' and unknown' AS "Concat unknown types";
937  Concat unknown types 
938 ----------------------
939  unknown and unknown
940 (1 row)
942 SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";
943  Concat text to unknown type 
944 -----------------------------
945  text and unknown
946 (1 row)
948 SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";
949  Concat char to unknown type 
950 -----------------------------
951  characters and text
952 (1 row)
954 SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";
955  Concat text to char 
956 ---------------------
957  text and characters
958 (1 row)
960 SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";
961  Concat text to varchar 
962 ------------------------
963  text and varchar
964 (1 row)
967 -- test substr with toasted text values
969 CREATE TABLE toasttest(f1 text);
970 insert into toasttest values(repeat('1234567890',10000));
971 insert into toasttest values(repeat('1234567890',10000));
973 -- Ensure that some values are uncompressed, to test the faster substring
974 -- operation used in that case
976 alter table toasttest alter column f1 set storage external;
977 insert into toasttest values(repeat('1234567890',10000));
978 insert into toasttest values(repeat('1234567890',10000));
979 -- If the starting position is zero or less, then return from the start of the string
980 -- adjusting the length to be consistent with the "negative start" per SQL92.
981 SELECT substr(f1, -1, 5) from toasttest;
982  substr 
983 --------
984  123
985  123
986  123
987  123
988 (4 rows)
990 -- If the length is less than zero, an ERROR is thrown.
991 SELECT substr(f1, 5, -1) from toasttest;
992 ERROR:  negative substring length not allowed
993 -- If no third argument (length) is provided, the length to the end of the
994 -- string is assumed.
995 SELECT substr(f1, 99995) from toasttest;
996  substr 
997 --------
998  567890
999  567890
1000  567890
1001  567890
1002 (4 rows)
1004 -- If start plus length is > string length, the result is truncated to
1005 -- string length
1006 SELECT substr(f1, 99995, 10) from toasttest;
1007  substr 
1008 --------
1009  567890
1010  567890
1011  567890
1012  567890
1013 (4 rows)
1015 DROP TABLE toasttest;
1017 -- test substr with toasted bytea values
1019 CREATE TABLE toasttest(f1 bytea);
1020 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1021 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1023 -- Ensure that some values are uncompressed, to test the faster substring
1024 -- operation used in that case
1026 alter table toasttest alter column f1 set storage external;
1027 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1028 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1029 -- If the starting position is zero or less, then return from the start of the string
1030 -- adjusting the length to be consistent with the "negative start" per SQL92.
1031 SELECT substr(f1, -1, 5) from toasttest;
1032  substr 
1033 --------
1034  123
1035  123
1036  123
1037  123
1038 (4 rows)
1040 -- If the length is less than zero, an ERROR is thrown.
1041 SELECT substr(f1, 5, -1) from toasttest;
1042 ERROR:  negative substring length not allowed
1043 -- If no third argument (length) is provided, the length to the end of the
1044 -- string is assumed.
1045 SELECT substr(f1, 99995) from toasttest;
1046  substr 
1047 --------
1048  567890
1049  567890
1050  567890
1051  567890
1052 (4 rows)
1054 -- If start plus length is > string length, the result is truncated to
1055 -- string length
1056 SELECT substr(f1, 99995, 10) from toasttest;
1057  substr 
1058 --------
1059  567890
1060  567890
1061  567890
1062  567890
1063 (4 rows)
1065 DROP TABLE toasttest;
1066 -- test internally compressing datums
1067 -- this tests compressing a datum to a very small size which exercises a
1068 -- corner case in packed-varlena handling: even though small, the compressed
1069 -- datum must be given a 4-byte header because there are no bits to indicate
1070 -- compression in a 1-byte header
1071 CREATE TABLE toasttest (c char(4096));
1072 INSERT INTO toasttest VALUES('x');
1073 SELECT length(c), c::text FROM toasttest;
1074  length | c 
1075 --------+---
1076       1 | x
1077 (1 row)
1079 SELECT c FROM toasttest;
1080                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 c                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
1081 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1082  x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
1083 (1 row)
1085 DROP TABLE toasttest;
1087 -- test length
1089 SELECT length('abcdef') AS "length_6";
1090  length_6 
1091 ----------
1092         6
1093 (1 row)
1096 -- test strpos
1098 SELECT strpos('abcdef', 'cd') AS "pos_3";
1099  pos_3 
1100 -------
1101      3
1102 (1 row)
1104 SELECT strpos('abcdef', 'xy') AS "pos_0";
1105  pos_0 
1106 -------
1107      0
1108 (1 row)
1111 -- test replace
1113 SELECT replace('abcdef', 'de', '45') AS "abc45f";
1114  abc45f 
1115 --------
1116  abc45f
1117 (1 row)
1119 SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
1120  ya123da123doo 
1121 ---------------
1122  ya123da123doo
1123 (1 row)
1125 SELECT replace('yabadoo', 'bad', '') AS "yaoo";
1126  yaoo 
1127 ------
1128  yaoo
1129 (1 row)
1132 -- test split_part
1134 select split_part('joeuser@mydatabase','@',0) AS "an error";
1135 ERROR:  field position must be greater than zero
1136 select split_part('joeuser@mydatabase','@',1) AS "joeuser";
1137  joeuser 
1138 ---------
1139  joeuser
1140 (1 row)
1142 select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
1143  mydatabase 
1144 ------------
1145  mydatabase
1146 (1 row)
1148 select split_part('joeuser@mydatabase','@',3) AS "empty string";
1149  empty string 
1150 --------------
1152 (1 row)
1154 select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
1155  joeuser 
1156 ---------
1157  joeuser
1158 (1 row)
1161 -- test to_hex
1163 select to_hex(256*256*256 - 1) AS "ffffff";
1164  ffffff 
1165 --------
1166  ffffff
1167 (1 row)
1169 select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
1170  ffffffff 
1171 ----------
1172  ffffffff
1173 (1 row)
1176 -- MD5 test suite - from IETF RFC 1321
1177 -- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)
1179 select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1180  TRUE 
1181 ------
1183 (1 row)
1185 select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1186  TRUE 
1187 ------
1189 (1 row)
1191 select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1192  TRUE 
1193 ------
1195 (1 row)
1197 select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1198  TRUE 
1199 ------
1201 (1 row)
1203 select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1204  TRUE 
1205 ------
1207 (1 row)
1209 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1210  TRUE 
1211 ------
1213 (1 row)
1215 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1216  TRUE 
1217 ------
1219 (1 row)
1221 select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1222  TRUE 
1223 ------
1225 (1 row)
1227 select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1228  TRUE 
1229 ------
1231 (1 row)
1233 select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1234  TRUE 
1235 ------
1237 (1 row)
1239 select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1240  TRUE 
1241 ------
1243 (1 row)
1245 select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1246  TRUE 
1247 ------
1249 (1 row)
1251 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1252  TRUE 
1253 ------
1255 (1 row)
1257 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1258  TRUE 
1259 ------
1261 (1 row)
1264 -- test behavior of escape_string_warning and standard_conforming_strings options
1266 set escape_string_warning = off;
1267 set standard_conforming_strings = off;
1268 show escape_string_warning;
1269  escape_string_warning 
1270 -----------------------
1271  off
1272 (1 row)
1274 show standard_conforming_strings;
1275  standard_conforming_strings 
1276 -----------------------------
1277  off
1278 (1 row)
1280 set escape_string_warning = on;
1281 set standard_conforming_strings = on;
1282 show escape_string_warning;
1283  escape_string_warning 
1284 -----------------------
1285  on
1286 (1 row)
1288 show standard_conforming_strings;
1289  standard_conforming_strings 
1290 -----------------------------
1291  on
1292 (1 row)
1294 select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\'   as f4, 'ab\''cd' as f5, '\\' as f6;
1295   f1   |   f2   |   f3    |  f4   |   f5   | f6 
1296 -------+--------+---------+-------+--------+----
1297  a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1298 (1 row)
1300 set standard_conforming_strings = off;
1301 select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\'   as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
1302 WARNING:  nonstandard use of \\ in a string literal
1303 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1304                ^
1305 HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.
1306 WARNING:  nonstandard use of \\ in a string literal
1307 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1308                                ^
1309 HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.
1310 WARNING:  nonstandard use of \\ in a string literal
1311 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1312                                                  ^
1313 HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.
1314 WARNING:  nonstandard use of \\ in a string literal
1315 LINE 1: ...bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\'  ...
1316                                                              ^
1317 HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.
1318 WARNING:  nonstandard use of \\ in a string literal
1319 LINE 1: ...'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\'   as f4, 'ab\\\'cd'...
1320                                                              ^
1321 HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.
1322 WARNING:  nonstandard use of \\ in a string literal
1323 LINE 1: ...'''cd' as f3, 'abcd\\'   as f4, 'ab\\\'cd' as f5, '\\\\' as ...
1324                                                              ^
1325 HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.
1326   f1   |   f2   |   f3    |  f4   |   f5   | f6 
1327 -------+--------+---------+-------+--------+----
1328  a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1329 (1 row)
1331 set escape_string_warning = off;
1332 set standard_conforming_strings = on;
1333 select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\'   as f4, 'ab\''cd' as f5, '\\' as f6;
1334   f1   |   f2   |   f3    |  f4   |   f5   | f6 
1335 -------+--------+---------+-------+--------+----
1336  a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1337 (1 row)
1339 set standard_conforming_strings = off;
1340 select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\'   as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
1341   f1   |   f2   |   f3    |  f4   |   f5   | f6 
1342 -------+--------+---------+-------+--------+----
1343  a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1344 (1 row)
1347 -- Additional string functions
1349 SELECT initcap('hi THOMAS');
1350   initcap  
1351 -----------
1352  Hi Thomas
1353 (1 row)
1355 SELECT lpad('hi', 5, 'xy');
1356  lpad  
1357 -------
1358  xyxhi
1359 (1 row)
1361 SELECT lpad('hi', 5);
1362  lpad  
1363 -------
1364     hi
1365 (1 row)
1367 SELECT lpad('hi', -5, 'xy');
1368  lpad 
1369 ------
1371 (1 row)
1373 SELECT lpad('hello', 2);
1374  lpad 
1375 ------
1376  he
1377 (1 row)
1379 SELECT lpad('hi', 5, '');
1380  lpad 
1381 ------
1382  hi
1383 (1 row)
1385 SELECT rpad('hi', 5, 'xy');
1386  rpad  
1387 -------
1388  hixyx
1389 (1 row)
1391 SELECT rpad('hi', 5);
1392  rpad  
1393 -------
1394  hi   
1395 (1 row)
1397 SELECT rpad('hi', -5, 'xy');
1398  rpad 
1399 ------
1401 (1 row)
1403 SELECT rpad('hello', 2);
1404  rpad 
1405 ------
1406  he
1407 (1 row)
1409 SELECT rpad('hi', 5, '');
1410  rpad 
1411 ------
1412  hi
1413 (1 row)
1415 SELECT ltrim('zzzytrim', 'xyz');
1416  ltrim 
1417 -------
1418  trim
1419 (1 row)
1421 SELECT translate('', '14', 'ax');
1422  translate 
1423 -----------
1425 (1 row)
1427 SELECT translate('12345', '14', 'ax');
1428  translate 
1429 -----------
1430  a23x5
1431 (1 row)
1433 SELECT ascii('x');
1434  ascii 
1435 -------
1436    120
1437 (1 row)
1439 SELECT ascii('');
1440  ascii 
1441 -------
1442      0
1443 (1 row)
1445 SELECT chr(65);
1446  chr 
1447 -----
1449 (1 row)
1451 SELECT chr(0);
1452 ERROR:  null character not permitted
1453 SELECT repeat('Pg', 4);
1454   repeat  
1455 ----------
1456  PgPgPgPg
1457 (1 row)
1459 SELECT repeat('Pg', -4);
1460  repeat 
1461 --------
1463 (1 row)
1465 SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea);
1466  btrim 
1467 -------
1468  Tom
1469 (1 row)
1471 SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
1472  btrim 
1473 -------
1474  trim
1475 (1 row)
1477 SELECT btrim(''::bytea, E'\\000'::bytea);
1478  btrim 
1479 -------
1481 (1 row)
1483 SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);
1484     btrim     
1485 --------------
1486  \000trim\000
1487 (1 row)