3 -- Test various data entry syntaxes.
5 -- SQL string continuation syntax
6 -- E021-03 character string literals
10 AS "Three lines to one";
12 -------------------------------------
13 first line - next line - third line
16 -- illegal string continuation syntax
18 ' - next line' /* this comment is not allowed here */
20 AS "Illegal comment within continuation";
21 ERROR: syntax error at or near "' - third line'"
22 LINE 3: ' - third line'
25 SET standard_conforming_strings TO on;
26 SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
32 SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
38 SELECT U&'a\\b' AS "a\b";
44 SELECT U&' \' UESCAPE '!' AS "tricky";
50 SELECT 'tricky' AS U&"\" UESCAPE '!';
56 SELECT U&'wrong: \061';
57 ERROR: invalid Unicode escape
58 LINE 1: SELECT U&'wrong: \061';
60 HINT: Unicode escapes must be \XXXX or \+XXXXXX.
61 SELECT U&'wrong: \+0061';
62 ERROR: invalid Unicode escape
63 LINE 1: SELECT U&'wrong: \+0061';
65 HINT: Unicode escapes must be \XXXX or \+XXXXXX.
66 SELECT U&'wrong: +0061' UESCAPE +;
67 ERROR: UESCAPE must be followed by a simple string literal at or near "+"
68 LINE 1: SELECT U&'wrong: +0061' UESCAPE +;
70 SELECT U&'wrong: +0061' UESCAPE '+';
71 ERROR: invalid Unicode escape character at or near "'+'"
72 LINE 1: SELECT U&'wrong: +0061' UESCAPE '+';
74 SELECT U&'wrong: \db99';
75 ERROR: invalid Unicode surrogate pair
76 LINE 1: SELECT U&'wrong: \db99';
78 SELECT U&'wrong: \db99xy';
79 ERROR: invalid Unicode surrogate pair
80 LINE 1: SELECT U&'wrong: \db99xy';
82 SELECT U&'wrong: \db99\\';
83 ERROR: invalid Unicode surrogate pair
84 LINE 1: SELECT U&'wrong: \db99\\';
86 SELECT U&'wrong: \db99\0061';
87 ERROR: invalid Unicode surrogate pair
88 LINE 1: SELECT U&'wrong: \db99\0061';
90 SELECT U&'wrong: \+00db99\+000061';
91 ERROR: invalid Unicode surrogate pair
92 LINE 1: SELECT U&'wrong: \+00db99\+000061';
94 SELECT U&'wrong: \+2FFFFF';
95 ERROR: invalid Unicode escape value
96 LINE 1: SELECT U&'wrong: \+2FFFFF';
98 -- while we're here, check the same cases in E-style literals
99 SELECT E'd\u0061t\U00000061' AS "data";
105 SELECT E'a\\b' AS "a\b";
111 SELECT E'wrong: \u061';
112 ERROR: invalid Unicode escape
113 LINE 1: SELECT E'wrong: \u061';
115 HINT: Unicode escapes must be \uXXXX or \UXXXXXXXX.
116 SELECT E'wrong: \U0061';
117 ERROR: invalid Unicode escape
118 LINE 1: SELECT E'wrong: \U0061';
120 HINT: Unicode escapes must be \uXXXX or \UXXXXXXXX.
121 SELECT E'wrong: \udb99';
122 ERROR: invalid Unicode surrogate pair at or near "'"
123 LINE 1: SELECT E'wrong: \udb99';
125 SELECT E'wrong: \udb99xy';
126 ERROR: invalid Unicode surrogate pair at or near "x"
127 LINE 1: SELECT E'wrong: \udb99xy';
129 SELECT E'wrong: \udb99\\';
130 ERROR: invalid Unicode surrogate pair at or near "\"
131 LINE 1: SELECT E'wrong: \udb99\\';
133 SELECT E'wrong: \udb99\u0061';
134 ERROR: invalid Unicode surrogate pair at or near "\u0061"
135 LINE 1: SELECT E'wrong: \udb99\u0061';
137 SELECT E'wrong: \U0000db99\U00000061';
138 ERROR: invalid Unicode surrogate pair at or near "\U00000061"
139 LINE 1: SELECT E'wrong: \U0000db99\U00000061';
141 SELECT E'wrong: \U002FFFFF';
142 ERROR: invalid Unicode escape value at or near "\U002FFFFF"
143 LINE 1: SELECT E'wrong: \U002FFFFF';
145 SET standard_conforming_strings TO off;
146 SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
147 ERROR: unsafe use of string constant with Unicode escapes
148 LINE 1: SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
150 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
151 SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
152 ERROR: unsafe use of string constant with Unicode escapes
153 LINE 1: SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061...
155 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
156 SELECT U&' \' UESCAPE '!' AS "tricky";
157 ERROR: unsafe use of string constant with Unicode escapes
158 LINE 1: SELECT U&' \' UESCAPE '!' AS "tricky";
160 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
161 SELECT 'tricky' AS U&"\" UESCAPE '!';
167 SELECT U&'wrong: \061';
168 ERROR: unsafe use of string constant with Unicode escapes
169 LINE 1: SELECT U&'wrong: \061';
171 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
172 SELECT U&'wrong: \+0061';
173 ERROR: unsafe use of string constant with Unicode escapes
174 LINE 1: SELECT U&'wrong: \+0061';
176 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
177 SELECT U&'wrong: +0061' UESCAPE '+';
178 ERROR: unsafe use of string constant with Unicode escapes
179 LINE 1: SELECT U&'wrong: +0061' UESCAPE '+';
181 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
182 RESET standard_conforming_strings;
184 SET bytea_output TO hex;
185 SELECT E'\\xDeAdBeEf'::bytea;
191 SELECT E'\\x De Ad Be Ef '::bytea;
197 SELECT E'\\xDeAdBeE'::bytea;
198 ERROR: invalid hexadecimal data: odd number of digits
199 LINE 1: SELECT E'\\xDeAdBeE'::bytea;
201 SELECT E'\\xDeAdBeEx'::bytea;
202 ERROR: invalid hexadecimal digit: "x"
203 LINE 1: SELECT E'\\xDeAdBeEx'::bytea;
205 SELECT E'\\xDe00BeEf'::bytea;
211 SELECT E'DeAdBeEf'::bytea;
217 SELECT E'De\\000dBeEf'::bytea;
223 SELECT E'De\123dBeEf'::bytea;
229 SELECT E'De\\123dBeEf'::bytea;
235 SELECT E'De\\678dBeEf'::bytea;
236 ERROR: invalid input syntax for type bytea
237 LINE 1: SELECT E'De\\678dBeEf'::bytea;
239 SET bytea_output TO escape;
240 SELECT E'\\xDeAdBeEf'::bytea;
246 SELECT E'\\x De Ad Be Ef '::bytea;
252 SELECT E'\\xDe00BeEf'::bytea;
258 SELECT E'DeAdBeEf'::bytea;
264 SELECT E'De\\000dBeEf'::bytea;
270 SELECT E'De\\123dBeEf'::bytea;
277 -- test conversions between various string types
278 -- E021-10 implicit casting among the character data types
280 SELECT CAST(f1 AS text) AS "text(char)" FROM CHAR_TBL;
289 SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL;
298 SELECT CAST(name 'namefield' AS text) AS "text(name)";
304 -- since this is an explicit cast, it should truncate w/o error:
305 SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL;
312 -- note: implicit-cast case is tested in char.sql
313 SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL;
315 ----------------------
320 SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL;
329 SELECT CAST(name 'namefield' AS char(10)) AS "char(name)";
335 SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL;
342 SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL;
351 SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)";
358 -- test SQL string functions
359 -- E### and T### are feature reference numbers from SQL99
361 -- E021-09 trim function
362 SELECT TRIM(BOTH FROM ' bunch o blanks ') = 'bunch o blanks' AS "bunch o blanks";
368 SELECT TRIM(LEADING FROM ' bunch o blanks ') = 'bunch o blanks ' AS "bunch o blanks ";
374 SELECT TRIM(TRAILING FROM ' bunch o blanks ') = ' bunch o blanks' AS " bunch o blanks";
380 SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs";
386 -- E021-06 substring expression
387 SELECT SUBSTRING('1234567890' FROM 3) = '34567890' AS "34567890";
393 SELECT SUBSTRING('1234567890' FROM 4 FOR 3) = '456' AS "456";
399 -- test overflow cases
400 SELECT SUBSTRING('string' FROM 2 FOR 2147483646) AS "tring";
406 SELECT SUBSTRING('string' FROM -10 FOR 2147483646) AS "string";
412 SELECT SUBSTRING('string' FROM -10 FOR -2147483646) AS "error";
413 ERROR: negative substring length not allowed
414 -- T581 regular expression substring (with SQL's bizarre regexp syntax)
415 SELECT SUBSTRING('abcdefg' SIMILAR 'a#"(b_d)#"%' ESCAPE '#') AS "bcd";
421 -- obsolete SQL99 syntax
422 SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd";
428 -- No match should return NULL
429 SELECT SUBSTRING('abcdefg' SIMILAR '#"(b_d)#"%' ESCAPE '#') IS NULL AS "True";
435 -- Null inputs should return NULL
436 SELECT SUBSTRING('abcdefg' SIMILAR '%' ESCAPE NULL) IS NULL AS "True";
442 SELECT SUBSTRING(NULL SIMILAR '%' ESCAPE '#') IS NULL AS "True";
448 SELECT SUBSTRING('abcdefg' SIMILAR NULL ESCAPE '#') IS NULL AS "True";
454 -- The first and last parts should act non-greedy
455 SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%#"g' ESCAPE '#') AS "bcdef";
461 SELECT SUBSTRING('abcdefg' SIMILAR 'a*#"%#"g*' ESCAPE '#') AS "abcdefg";
467 -- Vertical bar in any part affects only that part
468 SELECT SUBSTRING('abcdefg' SIMILAR 'a|b#"%#"g' ESCAPE '#') AS "bcdef";
474 SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%#"x|g' ESCAPE '#') AS "bcdef";
480 SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%|ab#"g' ESCAPE '#') AS "bcdef";
486 -- Can't have more than two part separators
487 SELECT SUBSTRING('abcdefg' SIMILAR 'a*#"%#"g*#"x' ESCAPE '#') AS "error";
488 ERROR: SQL regular expression may not contain more than two escape-double-quote separators
489 CONTEXT: SQL function "substring" statement 1
490 -- Postgres extension: with 0 or 1 separator, assume parts 1 and 3 are empty
491 SELECT SUBSTRING('abcdefg' SIMILAR 'a#"%g' ESCAPE '#') AS "bcdefg";
497 SELECT SUBSTRING('abcdefg' SIMILAR 'a%g' ESCAPE '#') AS "abcdefg";
503 -- substring() with just two arguments is not allowed by SQL spec;
504 -- we accept it, but we interpret the pattern as a POSIX regexp not SQL
505 SELECT SUBSTRING('abcdefg' FROM 'c.e') AS "cde";
511 -- With a parenthesized subexpression, return only what matches the subexpr
512 SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde";
518 -- Check case where we have a match, but not a subexpression match
519 SELECT SUBSTRING('foo' FROM 'foo(bar)?') IS NULL AS t;
525 -- Check behavior of SIMILAR TO, which uses largely the same regexp variant
526 SELECT 'abcdefg' SIMILAR TO '_bcd%' AS true;
532 SELECT 'abcdefg' SIMILAR TO 'bcd%' AS false;
538 SELECT 'abcdefg' SIMILAR TO '_bcd#%' ESCAPE '#' AS false;
544 SELECT 'abcd%' SIMILAR TO '_bcd#%' ESCAPE '#' AS true;
550 -- Postgres uses '\' as the default escape character, which is not per spec
551 SELECT 'abcdefg' SIMILAR TO '_bcd\%' AS false;
557 -- and an empty string to mean "no escape", which is also not per spec
558 SELECT 'abcd\efg' SIMILAR TO '_bcd\%' ESCAPE '' AS true;
564 -- these behaviors are per spec, though:
565 SELECT 'abcdefg' SIMILAR TO '_bcd%' ESCAPE NULL AS null;
571 SELECT 'abcdefg' SIMILAR TO '_bcd#%' ESCAPE '##' AS error;
572 ERROR: invalid escape string
573 HINT: Escape string must be empty or one character.
574 -- Test backslash escapes in regexp_replace's replacement string
575 SELECT regexp_replace('1112223333', E'(\\d{3})(\\d{3})(\\d{4})', E'(\\1) \\2-\\3');
581 SELECT regexp_replace('foobarrbazz', E'(.)\\1', E'X\\&Y', 'g');
587 SELECT regexp_replace('foobarrbazz', E'(.)\\1', E'X\\\\Y', 'g');
593 -- not an error, though perhaps it should be:
594 SELECT regexp_replace('foobarrbazz', E'(.)\\1', E'X\\Y\\1Z\\');
600 SELECT regexp_replace('AAA BBB CCC ', E'\\s+', ' ', 'g');
606 SELECT regexp_replace('AAA', '^|$', 'Z', 'g');
612 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi');
618 -- invalid regexp option
619 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'z');
620 ERROR: invalid regular expression option: "z"
621 -- extended regexp_replace tests
622 SELECT regexp_replace('A PostgreSQL function', 'A|e|i|o|u', 'X', 1);
624 -----------------------
625 X PostgreSQL function
628 SELECT regexp_replace('A PostgreSQL function', 'A|e|i|o|u', 'X', 1, 2);
630 -----------------------
631 A PXstgreSQL function
634 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 0, 'i');
636 -----------------------
637 X PXstgrXSQL fXnctXXn
640 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 1, 'i');
642 -----------------------
643 X PostgreSQL function
646 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 2, 'i');
648 -----------------------
649 A PXstgreSQL function
652 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 3, 'i');
654 -----------------------
655 A PostgrXSQL function
658 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 9, 'i');
660 -----------------------
661 A PostgreSQL function
664 SELECT regexp_replace('A PostgreSQL function', 'A|e|i|o|u', 'X', 7, 0, 'i');
666 -----------------------
667 A PostgrXSQL fXnctXXn
670 -- 'g' flag should be ignored when N is specified
671 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 1, 'g');
673 -----------------------
674 A PXstgreSQL function
678 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', -1, 0, 'i');
679 ERROR: invalid value for parameter "start": -1
680 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, -1, 'i');
681 ERROR: invalid value for parameter "n": -1
682 -- erroneous invocation of non-extended form
683 SELECT regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', '1');
684 ERROR: invalid regular expression option: "1"
685 HINT: If you meant to use regexp_replace() with a start parameter, cast the fourth argument to integer explicitly.
686 -- regexp_count tests
687 SELECT regexp_count('123123123123123', '(12)3');
693 SELECT regexp_count('123123123123', '123', 1);
699 SELECT regexp_count('123123123123', '123', 3);
705 SELECT regexp_count('123123123123', '123', 33);
711 SELECT regexp_count('ABCABCABCABC', 'Abc', 1, '');
717 SELECT regexp_count('ABCABCABCABC', 'Abc', 1, 'i');
724 SELECT regexp_count('123123123123', '123', 0);
725 ERROR: invalid value for parameter "start": 0
726 SELECT regexp_count('123123123123', '123', -3);
727 ERROR: invalid value for parameter "start": -3
729 SELECT regexp_like('Steven', '^Ste(v|ph)en$');
735 SELECT regexp_like('a'||CHR(10)||'d', 'a.d', 'n');
741 SELECT regexp_like('a'||CHR(10)||'d', 'a.d', 's');
747 SELECT regexp_like('abc', ' a . c ', 'x');
753 SELECT regexp_like('abc', 'a.c', 'g'); -- error
754 ERROR: regexp_like() does not support the "global" option
755 -- regexp_instr tests
756 SELECT regexp_instr('abcdefghi', 'd.f');
762 SELECT regexp_instr('abcdefghi', 'd.q');
768 SELECT regexp_instr('abcabcabc', 'a.c');
774 SELECT regexp_instr('abcabcabc', 'a.c', 2);
780 SELECT regexp_instr('abcabcabc', 'a.c', 1, 3);
786 SELECT regexp_instr('abcabcabc', 'a.c', 1, 4);
792 SELECT regexp_instr('abcabcabc', 'A.C', 1, 2, 0, 'i');
798 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 0, 'i', 0);
804 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 0, 'i', 1);
810 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 0, 'i', 2);
816 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 0, 'i', 3);
822 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 0, 'i', 4);
828 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 0, 'i', 5);
834 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 1, 'i', 0);
840 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 1, 'i', 1);
846 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 1, 'i', 2);
852 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 1, 'i', 3);
858 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 1, 'i', 4);
864 SELECT regexp_instr('1234567890', '(123)(4(56)(78))', 1, 1, 1, 'i', 5);
870 -- Check case where we have a match, but not a subexpression match
871 SELECT regexp_instr('foo', 'foo(bar)?', 1, 1, 0, '', 1);
878 SELECT regexp_instr('abcabcabc', 'a.c', 0, 1);
879 ERROR: invalid value for parameter "start": 0
880 SELECT regexp_instr('abcabcabc', 'a.c', 1, 0);
881 ERROR: invalid value for parameter "n": 0
882 SELECT regexp_instr('abcabcabc', 'a.c', 1, 1, -1);
883 ERROR: invalid value for parameter "endoption": -1
884 SELECT regexp_instr('abcabcabc', 'a.c', 1, 1, 2);
885 ERROR: invalid value for parameter "endoption": 2
886 SELECT regexp_instr('abcabcabc', 'a.c', 1, 1, 0, 'g');
887 ERROR: regexp_instr() does not support the "global" option
888 SELECT regexp_instr('abcabcabc', 'a.c', 1, 1, 0, '', -1);
889 ERROR: invalid value for parameter "subexpr": -1
890 -- regexp_substr tests
891 SELECT regexp_substr('abcdefghi', 'd.f');
897 SELECT regexp_substr('abcdefghi', 'd.q') IS NULL AS t;
903 SELECT regexp_substr('abcabcabc', 'a.c');
909 SELECT regexp_substr('abcabcabc', 'a.c', 2);
915 SELECT regexp_substr('abcabcabc', 'a.c', 1, 3);
921 SELECT regexp_substr('abcabcabc', 'a.c', 1, 4) IS NULL AS t;
927 SELECT regexp_substr('abcabcabc', 'A.C', 1, 2, 'i');
933 SELECT regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 0);
939 SELECT regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 1);
945 SELECT regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 2);
951 SELECT regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 3);
957 SELECT regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 4);
963 SELECT regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 5) IS NULL AS t;
969 -- Check case where we have a match, but not a subexpression match
970 SELECT regexp_substr('foo', 'foo(bar)?', 1, 1, '', 1) IS NULL AS t;
977 SELECT regexp_substr('abcabcabc', 'a.c', 0, 1);
978 ERROR: invalid value for parameter "start": 0
979 SELECT regexp_substr('abcabcabc', 'a.c', 1, 0);
980 ERROR: invalid value for parameter "n": 0
981 SELECT regexp_substr('abcabcabc', 'a.c', 1, 1, 'g');
982 ERROR: regexp_substr() does not support the "global" option
983 SELECT regexp_substr('abcabcabc', 'a.c', 1, 1, '', -1);
984 ERROR: invalid value for parameter "subexpr": -1
985 -- set so we can tell NULL from empty string
987 -- return all matches from regexp
988 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$);
994 -- test case insensitive
995 SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i');
1001 -- global option - more than one match
1002 SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g');
1009 -- empty capture group (matched empty string)
1010 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$);
1017 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$);
1022 -- optional capture group did not match, null entry in array
1023 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$);
1029 -- no capture groups
1030 SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$);
1036 -- start/end-of-line matches are of zero length
1037 SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '^', 'mg');
1046 SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '$', 'mg');
1055 SELECT regexp_matches('1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '^.?', 'mg');
1065 SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '.?$', 'mg');
1080 SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4', '.?$', 'mg');
1095 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$, 'gz');
1096 ERROR: invalid regular expression option: "z"
1097 SELECT regexp_matches('foobarbequebaz', $re$(barbeque$re$);
1098 ERROR: invalid regular expression: parentheses () not balanced
1099 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque){2,1}$re$);
1100 ERROR: invalid regular expression: invalid repetition count(s)
1101 -- split string on regexp
1102 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', $re$\s+$re$) AS foo;
1116 SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', $re$\s+$re$);
1117 regexp_split_to_array
1118 -----------------------------------------------
1119 {the,quick,brown,fox,jumps,over,the,lazy,dog}
1122 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', $re$\s*$re$) AS foo;
1162 SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', $re$\s*$re$);
1163 regexp_split_to_array
1164 -------------------------------------------------------------------------
1165 {t,h,e,q,u,i,c,k,b,r,o,w,n,f,o,x,j,u,m,p,s,o,v,e,r,t,h,e,l,a,z,y,d,o,g}
1168 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', '') AS foo;
1216 SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', '');
1217 regexp_split_to_array
1218 ---------------------------------------------------------------------------------------------------------
1219 {t,h,e," ",q,u,i,c,k," ",b,r,o,w,n," ",f,o,x," ",j,u,m,p,s," ",o,v,e,r," ",t,h,e," ",l,a,z,y," ",d,o,g}
1223 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i') AS foo;
1225 ---------------------------+--------
1227 QUick bROWn FOx jUMPs ov | 25
1232 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i');
1233 regexp_split_to_array
1234 -----------------------------------------------------
1235 {th," QUick bROWn FOx jUMPs ov","r Th"," lazy dOG"}
1238 -- no match of pattern
1239 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', 'nomatch') AS foo;
1241 ---------------------------------------------+--------
1242 the quick brown fox jumps over the lazy dog | 43
1245 SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', 'nomatch');
1246 regexp_split_to_array
1247 -------------------------------------------------
1248 {"the quick brown fox jumps over the lazy dog"}
1251 -- some corner cases
1252 SELECT regexp_split_to_array('123456','1');
1253 regexp_split_to_array
1254 -----------------------
1258 SELECT regexp_split_to_array('123456','6');
1259 regexp_split_to_array
1260 -----------------------
1264 SELECT regexp_split_to_array('123456','.');
1265 regexp_split_to_array
1266 ------------------------
1267 {"","","","","","",""}
1270 SELECT regexp_split_to_array('123456','');
1271 regexp_split_to_array
1272 -----------------------
1276 SELECT regexp_split_to_array('123456','(?:)');
1277 regexp_split_to_array
1278 -----------------------
1282 SELECT regexp_split_to_array('1','');
1283 regexp_split_to_array
1284 -----------------------
1289 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'zippy') AS foo;
1290 ERROR: invalid regular expression option: "z"
1291 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'iz');
1292 ERROR: invalid regular expression option: "z"
1293 -- global option meaningless for regexp_split
1294 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g') AS foo;
1295 ERROR: regexp_split_to_table() does not support the "global" option
1296 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g');
1297 ERROR: regexp_split_to_array() does not support the "global" option
1298 -- change NULL-display back
1300 -- E021-11 position expression
1301 SELECT POSITION('4' IN '1234567890') = '4' AS "4";
1307 SELECT POSITION('5' IN '1234567890') = '5' AS "5";
1313 -- T312 character overlay function
1314 SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
1320 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5) AS "yabadaba";
1326 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5 FOR 0) AS "yabadabadoo";
1332 SELECT OVERLAY('babosa' PLACING 'ubb' FROM 2 FOR 4) AS "bubba";
1340 -- Be sure to form every test as a LIKE/NOT LIKE pair.
1342 -- simplest examples
1343 -- E061-04 like predicate
1344 SELECT 'hawkeye' LIKE 'h%' AS "true";
1350 SELECT 'hawkeye' NOT LIKE 'h%' AS "false";
1356 SELECT 'hawkeye' LIKE 'H%' AS "false";
1362 SELECT 'hawkeye' NOT LIKE 'H%' AS "true";
1368 SELECT 'hawkeye' LIKE 'indio%' AS "false";
1374 SELECT 'hawkeye' NOT LIKE 'indio%' AS "true";
1380 SELECT 'hawkeye' LIKE 'h%eye' AS "true";
1386 SELECT 'hawkeye' NOT LIKE 'h%eye' AS "false";
1392 SELECT 'indio' LIKE '_ndio' AS "true";
1398 SELECT 'indio' NOT LIKE '_ndio' AS "false";
1404 SELECT 'indio' LIKE 'in__o' AS "true";
1410 SELECT 'indio' NOT LIKE 'in__o' AS "false";
1416 SELECT 'indio' LIKE 'in_o' AS "false";
1422 SELECT 'indio' NOT LIKE 'in_o' AS "true";
1428 SELECT 'abc'::name LIKE '_b_' AS "true";
1434 SELECT 'abc'::name NOT LIKE '_b_' AS "false";
1440 SELECT 'abc'::bytea LIKE '_b_'::bytea AS "true";
1446 SELECT 'abc'::bytea NOT LIKE '_b_'::bytea AS "false";
1452 -- unused escape character
1453 SELECT 'hawkeye' LIKE 'h%' ESCAPE '#' AS "true";
1459 SELECT 'hawkeye' NOT LIKE 'h%' ESCAPE '#' AS "false";
1465 SELECT 'indio' LIKE 'ind_o' ESCAPE '$' AS "true";
1471 SELECT 'indio' NOT LIKE 'ind_o' ESCAPE '$' AS "false";
1478 -- E061-05 like predicate with escape clause
1479 SELECT 'h%' LIKE 'h#%' ESCAPE '#' AS "true";
1485 SELECT 'h%' NOT LIKE 'h#%' ESCAPE '#' AS "false";
1491 SELECT 'h%wkeye' LIKE 'h#%' ESCAPE '#' AS "false";
1497 SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true";
1503 SELECT 'h%wkeye' LIKE 'h#%%' ESCAPE '#' AS "true";
1509 SELECT 'h%wkeye' NOT LIKE 'h#%%' ESCAPE '#' AS "false";
1515 SELECT 'h%awkeye' LIKE 'h#%a%k%e' ESCAPE '#' AS "true";
1521 SELECT 'h%awkeye' NOT LIKE 'h#%a%k%e' ESCAPE '#' AS "false";
1527 SELECT 'indio' LIKE '_ndio' ESCAPE '$' AS "true";
1533 SELECT 'indio' NOT LIKE '_ndio' ESCAPE '$' AS "false";
1539 SELECT 'i_dio' LIKE 'i$_d_o' ESCAPE '$' AS "true";
1545 SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false";
1551 SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false";
1557 SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true";
1563 SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true";
1569 SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false";
1575 SELECT 'a_c'::bytea LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "true";
1581 SELECT 'a_c'::bytea NOT LIKE 'a$__'::bytea ESCAPE '$'::bytea AS "false";
1587 -- escape character same as pattern character
1588 SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true";
1594 SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false";
1600 SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true";
1606 SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false";
1612 SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true";
1618 SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false";
1624 SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true";
1630 SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false";
1636 SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false";
1642 SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true";
1649 -- test ILIKE (case-insensitive LIKE)
1650 -- Be sure to form every test as an ILIKE/NOT ILIKE pair.
1652 SELECT 'hawkeye' ILIKE 'h%' AS "true";
1658 SELECT 'hawkeye' NOT ILIKE 'h%' AS "false";
1664 SELECT 'hawkeye' ILIKE 'H%' AS "true";
1670 SELECT 'hawkeye' NOT ILIKE 'H%' AS "false";
1676 SELECT 'hawkeye' ILIKE 'H%Eye' AS "true";
1682 SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false";
1688 SELECT 'Hawkeye' ILIKE 'h%' AS "true";
1694 SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false";
1700 SELECT 'ABC'::name ILIKE '_b_' AS "true";
1706 SELECT 'ABC'::name NOT ILIKE '_b_' AS "false";
1713 -- test %/_ combination cases, cf bugs #4821 and #5478
1715 SELECT 'foo' LIKE '_%' as t, 'f' LIKE '_%' as t, '' LIKE '_%' as f;
1721 SELECT 'foo' LIKE '%_' as t, 'f' LIKE '%_' as t, '' LIKE '%_' as f;
1727 SELECT 'foo' LIKE '__%' as t, 'foo' LIKE '___%' as t, 'foo' LIKE '____%' as f;
1733 SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f;
1739 SELECT 'jack' LIKE '%____%' AS t;
1746 -- basic tests of LIKE with indexes
1748 CREATE TABLE texttest (a text PRIMARY KEY, b int);
1749 SELECT * FROM texttest WHERE a LIKE '%1%';
1754 CREATE TABLE byteatest (a bytea PRIMARY KEY, b int);
1755 SELECT * FROM byteatest WHERE a LIKE '%1%';
1760 DROP TABLE texttest, byteatest;
1762 -- test implicit type conversion
1764 -- E021-07 character concatenation
1765 SELECT 'unknown' || ' and unknown' AS "Concat unknown types";
1766 Concat unknown types
1767 ----------------------
1771 SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";
1772 Concat text to unknown type
1773 -----------------------------
1777 SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";
1778 Concat char to unknown type
1779 -----------------------------
1783 SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";
1785 ---------------------
1789 SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";
1790 Concat text to varchar
1791 ------------------------
1796 -- test substr with toasted text values
1798 CREATE TABLE toasttest(f1 text);
1799 insert into toasttest values(repeat('1234567890',10000));
1800 insert into toasttest values(repeat('1234567890',10000));
1802 -- Ensure that some values are uncompressed, to test the faster substring
1803 -- operation used in that case
1805 alter table toasttest alter column f1 set storage external;
1806 insert into toasttest values(repeat('1234567890',10000));
1807 insert into toasttest values(repeat('1234567890',10000));
1808 -- If the starting position is zero or less, then return from the start of the string
1809 -- adjusting the length to be consistent with the "negative start" per SQL.
1810 SELECT substr(f1, -1, 5) from toasttest;
1819 -- If the length is less than zero, an ERROR is thrown.
1820 SELECT substr(f1, 5, -1) from toasttest;
1821 ERROR: negative substring length not allowed
1822 -- If no third argument (length) is provided, the length to the end of the
1823 -- string is assumed.
1824 SELECT substr(f1, 99995) from toasttest;
1833 -- If start plus length is > string length, the result is truncated to
1835 SELECT substr(f1, 99995, 10) from toasttest;
1844 TRUNCATE TABLE toasttest;
1845 INSERT INTO toasttest values (repeat('1234567890',300));
1846 INSERT INTO toasttest values (repeat('1234567890',300));
1847 INSERT INTO toasttest values (repeat('1234567890',300));
1848 INSERT INTO toasttest values (repeat('1234567890',300));
1850 SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
1851 FROM pg_class where relname = 'toasttest';
1857 TRUNCATE TABLE toasttest;
1858 ALTER TABLE toasttest set (toast_tuple_target = 4080);
1859 INSERT INTO toasttest values (repeat('1234567890',300));
1860 INSERT INTO toasttest values (repeat('1234567890',300));
1861 INSERT INTO toasttest values (repeat('1234567890',300));
1862 INSERT INTO toasttest values (repeat('1234567890',300));
1864 SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
1865 FROM pg_class where relname = 'toasttest';
1871 DROP TABLE toasttest;
1873 -- test substr with toasted bytea values
1875 CREATE TABLE toasttest(f1 bytea);
1876 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1877 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1879 -- Ensure that some values are uncompressed, to test the faster substring
1880 -- operation used in that case
1882 alter table toasttest alter column f1 set storage external;
1883 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1884 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1885 -- If the starting position is zero or less, then return from the start of the string
1886 -- adjusting the length to be consistent with the "negative start" per SQL.
1887 SELECT substr(f1, -1, 5) from toasttest;
1896 -- If the length is less than zero, an ERROR is thrown.
1897 SELECT substr(f1, 5, -1) from toasttest;
1898 ERROR: negative substring length not allowed
1899 -- If no third argument (length) is provided, the length to the end of the
1900 -- string is assumed.
1901 SELECT substr(f1, 99995) from toasttest;
1910 -- If start plus length is > string length, the result is truncated to
1912 SELECT substr(f1, 99995, 10) from toasttest;
1921 DROP TABLE toasttest;
1922 -- test internally compressing datums
1923 -- this tests compressing a datum to a very small size which exercises a
1924 -- corner case in packed-varlena handling: even though small, the compressed
1925 -- datum must be given a 4-byte header because there are no bits to indicate
1926 -- compression in a 1-byte header
1927 CREATE TABLE toasttest (c char(4096));
1928 INSERT INTO toasttest VALUES('x');
1929 SELECT length(c), c::text FROM toasttest;
1935 SELECT c FROM toasttest;
1937 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1941 DROP TABLE toasttest;
1945 SELECT length('abcdef') AS "length_6";
1954 SELECT strpos('abcdef', 'cd') AS "pos_3";
1960 SELECT strpos('abcdef', 'xy') AS "pos_0";
1966 SELECT strpos('abcdef', '') AS "pos_1";
1972 SELECT strpos('', 'xy') AS "pos_0";
1978 SELECT strpos('', '') AS "pos_1";
1987 SELECT replace('abcdef', 'de', '45') AS "abc45f";
1993 SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
1999 SELECT replace('yabadoo', 'bad', '') AS "yaoo";
2008 select split_part('','@',1) AS "empty string";
2014 select split_part('','@',-1) AS "empty string";
2020 select split_part('joeuser@mydatabase','',1) AS "joeuser@mydatabase";
2022 --------------------
2026 select split_part('joeuser@mydatabase','',2) AS "empty string";
2032 select split_part('joeuser@mydatabase','',-1) AS "joeuser@mydatabase";
2034 --------------------
2038 select split_part('joeuser@mydatabase','',-2) AS "empty string";
2044 select split_part('joeuser@mydatabase','@',0) AS "an error";
2045 ERROR: field position must not be zero
2046 select split_part('joeuser@mydatabase','@@',1) AS "joeuser@mydatabase";
2048 --------------------
2052 select split_part('joeuser@mydatabase','@@',2) AS "empty string";
2058 select split_part('joeuser@mydatabase','@',1) AS "joeuser";
2064 select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
2070 select split_part('joeuser@mydatabase','@',3) AS "empty string";
2076 select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
2082 select split_part('joeuser@mydatabase','@',-1) AS "mydatabase";
2088 select split_part('joeuser@mydatabase','@',-2) AS "joeuser";
2094 select split_part('joeuser@mydatabase','@',-3) AS "empty string";
2100 select split_part('@joeuser@mydatabase@','@',-2) AS "mydatabase";
2109 select to_hex(256*256*256 - 1) AS "ffffff";
2115 select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
2122 -- MD5 test suite - from IETF RFC 1321
2123 -- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)
2125 select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
2131 select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
2137 select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
2143 select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
2149 select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
2155 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
2161 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
2167 select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
2173 select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
2179 select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
2185 select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
2191 select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
2197 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
2203 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
2212 SET bytea_output TO hex;
2215 ------------------------------------------------------------
2216 \xd14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
2219 SELECT sha224('The quick brown fox jumps over the lazy dog.');
2221 ------------------------------------------------------------
2222 \x619cba8e8e05826e9b8c519c0a5c68f4fb653e8a3d8aa04bb2c8cd4c
2227 --------------------------------------------------------------------
2228 \xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
2231 SELECT sha256('The quick brown fox jumps over the lazy dog.');
2233 --------------------------------------------------------------------
2234 \xef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c
2239 ----------------------------------------------------------------------------------------------------
2240 \x38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
2243 SELECT sha384('The quick brown fox jumps over the lazy dog.');
2245 ----------------------------------------------------------------------------------------------------
2246 \xed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7
2251 ------------------------------------------------------------------------------------------------------------------------------------
2252 \xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
2255 SELECT sha512('The quick brown fox jumps over the lazy dog.');
2257 ------------------------------------------------------------------------------------------------------------------------------------
2258 \x91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed
2264 SELECT encode('\x1234567890abcdef00', 'hex');
2266 --------------------
2270 SELECT decode('1234567890abcdef00', 'hex');
2272 ----------------------
2273 \x1234567890abcdef00
2276 SELECT encode(('\x' || repeat('1234567890abcdef0001', 7))::bytea, 'base64');
2278 ------------------------------------------------------------------------------
2279 EjRWeJCrze8AARI0VniQq83vAAESNFZ4kKvN7wABEjRWeJCrze8AARI0VniQq83vAAESNFZ4kKvN+
2280 7wABEjRWeJCrze8AAQ==
2283 SELECT decode(encode(('\x' || repeat('1234567890abcdef0001', 7))::bytea,
2284 'base64'), 'base64');
2286 ------------------------------------------------------------------------------------------------------------------------------------------------
2287 \x1234567890abcdef00011234567890abcdef00011234567890abcdef00011234567890abcdef00011234567890abcdef00011234567890abcdef00011234567890abcdef0001
2290 SELECT encode('\x1234567890abcdef00', 'escape');
2292 -----------------------------
2293 \x124Vx\220\253\315\357\000
2296 SELECT decode(encode('\x1234567890abcdef00', 'escape'), 'escape');
2298 ----------------------
2299 \x1234567890abcdef00
2303 -- get_bit/set_bit etc
2305 SELECT get_bit('\x1234567890abcdef00'::bytea, 43);
2311 SELECT get_bit('\x1234567890abcdef00'::bytea, 99); -- error
2312 ERROR: index 99 out of valid range, 0..71
2313 SELECT set_bit('\x1234567890abcdef00'::bytea, 43, 0);
2315 ----------------------
2316 \x1234567890a3cdef00
2319 SELECT set_bit('\x1234567890abcdef00'::bytea, 99, 0); -- error
2320 ERROR: index 99 out of valid range, 0..71
2321 SELECT get_byte('\x1234567890abcdef00'::bytea, 3);
2327 SELECT get_byte('\x1234567890abcdef00'::bytea, 99); -- error
2328 ERROR: index 99 out of valid range, 0..8
2329 SELECT set_byte('\x1234567890abcdef00'::bytea, 7, 11);
2331 ----------------------
2332 \x1234567890abcd0b00
2335 SELECT set_byte('\x1234567890abcdef00'::bytea, 99, 11); -- error
2336 ERROR: index 99 out of valid range, 0..8
2338 -- test behavior of escape_string_warning and standard_conforming_strings options
2340 set escape_string_warning = off;
2341 set standard_conforming_strings = off;
2342 show escape_string_warning;
2343 escape_string_warning
2344 -----------------------
2348 show standard_conforming_strings;
2349 standard_conforming_strings
2350 -----------------------------
2354 set escape_string_warning = on;
2355 set standard_conforming_strings = on;
2356 show escape_string_warning;
2357 escape_string_warning
2358 -----------------------
2362 show standard_conforming_strings;
2363 standard_conforming_strings
2364 -----------------------------
2368 select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
2369 f1 | f2 | f3 | f4 | f5 | f6
2370 -------+--------+---------+-------+--------+----
2371 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
2374 set standard_conforming_strings = off;
2375 select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
2376 WARNING: nonstandard use of \\ in a string literal
2377 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
2379 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
2380 WARNING: nonstandard use of \\ in a string literal
2381 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
2383 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
2384 WARNING: nonstandard use of \\ in a string literal
2385 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
2387 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
2388 WARNING: nonstandard use of \\ in a string literal
2389 LINE 1: ...bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' ...
2391 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
2392 WARNING: nonstandard use of \\ in a string literal
2393 LINE 1: ...'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd'...
2395 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
2396 WARNING: nonstandard use of \\ in a string literal
2397 LINE 1: ...'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as ...
2399 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
2400 f1 | f2 | f3 | f4 | f5 | f6
2401 -------+--------+---------+-------+--------+----
2402 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
2405 set escape_string_warning = off;
2406 set standard_conforming_strings = on;
2407 select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
2408 f1 | f2 | f3 | f4 | f5 | f6
2409 -------+--------+---------+-------+--------+----
2410 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
2413 set standard_conforming_strings = off;
2414 select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
2415 f1 | f2 | f3 | f4 | f5 | f6
2416 -------+--------+---------+-------+--------+----
2417 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
2420 reset standard_conforming_strings;
2422 -- Additional string functions
2424 SET bytea_output TO escape;
2425 SELECT initcap('hi THOMAS');
2431 SELECT lpad('hi', 5, 'xy');
2437 SELECT lpad('hi', 5);
2443 SELECT lpad('hi', -5, 'xy');
2449 SELECT lpad('hello', 2);
2455 SELECT lpad('hi', 5, '');
2461 SELECT rpad('hi', 5, 'xy');
2467 SELECT rpad('hi', 5);
2473 SELECT rpad('hi', -5, 'xy');
2479 SELECT rpad('hello', 2);
2485 SELECT rpad('hi', 5, '');
2491 SELECT ltrim('zzzytrim', 'xyz');
2497 SELECT translate('', '14', 'ax');
2503 SELECT translate('12345', '14', 'ax');
2528 ERROR: null character not permitted
2529 SELECT repeat('Pg', 4);
2535 SELECT repeat('Pg', -4);
2541 SELECT SUBSTRING('1234567890'::bytea FROM 3) "34567890";
2547 SELECT SUBSTRING('1234567890'::bytea FROM 4 FOR 3) AS "456";
2553 SELECT SUBSTRING('string'::bytea FROM 2 FOR 2147483646) AS "tring";
2559 SELECT SUBSTRING('string'::bytea FROM -10 FOR 2147483646) AS "string";
2565 SELECT SUBSTRING('string'::bytea FROM -10 FOR -2147483646) AS "error";
2566 ERROR: negative substring length not allowed
2567 SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea);
2573 SELECT trim(leading E'\\000'::bytea from E'\\000Tom\\000'::bytea);
2579 SELECT trim(trailing E'\\000'::bytea from E'\\000Tom\\000'::bytea);
2585 SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
2591 SELECT btrim(''::bytea, E'\\000'::bytea);
2597 SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);
2603 SELECT encode(overlay(E'Th\\000omas'::bytea placing E'Th\\001omas'::bytea from 2),'escape');
2609 SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 8),'escape');
2611 --------------------
2615 SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 5 for 3),'escape');
2621 SELECT bit_count('\x1234567890'::bytea);
2627 SELECT unistr('\0064at\+0000610');
2633 SELECT unistr('d\u0061t\U000000610');
2639 SELECT unistr('a\\b');
2646 SELECT unistr('wrong: \db99');
2647 ERROR: invalid Unicode surrogate pair
2648 SELECT unistr('wrong: \db99\0061');
2649 ERROR: invalid Unicode surrogate pair
2650 SELECT unistr('wrong: \+00db99\+000061');
2651 ERROR: invalid Unicode surrogate pair
2652 SELECT unistr('wrong: \+2FFFFF');
2653 ERROR: invalid Unicode code point: 2FFFFF
2654 SELECT unistr('wrong: \udb99\u0061');
2655 ERROR: invalid Unicode surrogate pair
2656 SELECT unistr('wrong: \U0000db99\U00000061');
2657 ERROR: invalid Unicode surrogate pair
2658 SELECT unistr('wrong: \U002FFFFF');
2659 ERROR: invalid Unicode code point: 2FFFFF
2660 SELECT unistr('wrong: \xyz');
2661 ERROR: invalid Unicode escape
2662 HINT: Unicode escapes must be \XXXX, \+XXXXXX, \uXXXX, or \UXXXXXXXX.