3 -- Test various data entry syntaxes.
5 -- SQL92 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&' \' UESCAPE '!' AS "tricky";
44 SELECT 'tricky' AS U&"\" UESCAPE '!';
50 SELECT U&'wrong: \061';
51 ERROR: invalid Unicode escape value at or near "\061'"
52 LINE 1: SELECT U&'wrong: \061';
54 SELECT U&'wrong: \+0061';
55 ERROR: invalid Unicode escape value at or near "\+0061'"
56 LINE 1: SELECT U&'wrong: \+0061';
58 SELECT U&'wrong: +0061' UESCAPE '+';
59 ERROR: invalid Unicode escape character at or near "+'"
60 LINE 1: SELECT U&'wrong: +0061' UESCAPE '+';
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";
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...
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";
77 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
78 SELECT 'tricky' AS U&"\" UESCAPE '!';
84 SELECT U&'wrong: \061';
85 ERROR: unsafe use of string constant with Unicode escapes
86 LINE 1: SELECT U&'wrong: \061';
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';
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 '+';
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;
113 SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL;
122 SELECT CAST(name 'namefield' AS text) AS "text(name)";
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;
136 -- note: implicit-cast case is tested in char.sql
137 SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL;
139 ----------------------
144 SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL;
153 SELECT CAST(name 'namefield' AS char(10)) AS "char(name)";
159 SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL;
166 SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL;
175 SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)";
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";
192 SELECT TRIM(LEADING FROM ' bunch o blanks ') = 'bunch o blanks ' AS "bunch o blanks ";
198 SELECT TRIM(TRAILING FROM ' bunch o blanks ') = ' bunch o blanks' AS " bunch o blanks";
204 SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs";
210 -- E021-06 substring expression
211 SELECT SUBSTRING('1234567890' FROM 3) = '34567890' AS "34567890";
217 SELECT SUBSTRING('1234567890' FROM 4 FOR 3) = '456' AS "456";
223 -- T581 regular expression substring (with SQL99's bizarre regexp syntax)
224 SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd";
230 -- No match should return NULL
231 SELECT SUBSTRING('abcdefg' FROM '#"(b_d)#"%' FOR '#') IS NULL AS "True";
237 -- Null inputs should return NULL
238 SELECT SUBSTRING('abcdefg' FROM '(b|c)' FOR NULL) IS NULL AS "True";
244 SELECT SUBSTRING(NULL FROM '(b|c)' FOR '#') IS NULL AS "True";
250 SELECT SUBSTRING('abcdefg' FROM NULL FOR '#') IS NULL AS "True";
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";
264 -- With a parenthesized subexpression, return only what matches the subexpr
265 SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde";
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');
278 SELECT regexp_replace('AAA BBB CCC ', E'\\s+', ' ', 'g');
284 SELECT regexp_replace('AAA', '^|$', 'Z', 'g');
290 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi');
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
301 -- return all matches from regexp
302 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$);
308 -- test case insensitive
309 SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i');
315 -- global option - more than one match
316 SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g');
323 -- empty capture group (matched empty string)
324 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$);
331 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$);
336 -- optional capture group did not match, null entry in array
337 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$);
344 SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$);
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;
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}
378 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', $re$\s*$re$) AS foo;
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}
425 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', '') AS foo;
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}
481 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'i') AS foo;
483 -----------------------+--------
485 QUick bROWn FOx jUMP | 21
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"}
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;
500 ----------------------------------------------+--------
501 the quick brown fox jumped over the lazy dog | 44
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"}
511 SELECT regexp_split_to_array('123456','1');
512 regexp_split_to_array
513 -----------------------
517 SELECT regexp_split_to_array('123456','6');
518 regexp_split_to_array
519 -----------------------
523 SELECT regexp_split_to_array('123456','.');
524 regexp_split_to_array
525 ------------------------
526 {"","","","","","",""}
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
541 -- E021-11 position expression
542 SELECT POSITION('4' IN '1234567890') = '4' AS "4";
548 SELECT POSITION('5' IN '1234567890') = '5' AS "5";
554 -- T312 character overlay function
555 SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
561 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5) AS "yabadaba";
567 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5 FOR 0) AS "yabadabadoo";
573 SELECT OVERLAY('babosa' PLACING 'ubb' FROM 2 FOR 4) AS "bubba";
581 -- Be sure to form every test as a LIKE/NOT LIKE pair.
584 -- E061-04 like predicate
585 SELECT 'hawkeye' LIKE 'h%' AS "true";
591 SELECT 'hawkeye' NOT LIKE 'h%' AS "false";
597 SELECT 'hawkeye' LIKE 'H%' AS "false";
603 SELECT 'hawkeye' NOT LIKE 'H%' AS "true";
609 SELECT 'hawkeye' LIKE 'indio%' AS "false";
615 SELECT 'hawkeye' NOT LIKE 'indio%' AS "true";
621 SELECT 'hawkeye' LIKE 'h%eye' AS "true";
627 SELECT 'hawkeye' NOT LIKE 'h%eye' AS "false";
633 SELECT 'indio' LIKE '_ndio' AS "true";
639 SELECT 'indio' NOT LIKE '_ndio' AS "false";
645 SELECT 'indio' LIKE 'in__o' AS "true";
651 SELECT 'indio' NOT LIKE 'in__o' AS "false";
657 SELECT 'indio' LIKE 'in_o' AS "false";
663 SELECT 'indio' NOT LIKE 'in_o' AS "true";
669 -- unused escape character
670 SELECT 'hawkeye' LIKE 'h%' ESCAPE '#' AS "true";
676 SELECT 'hawkeye' NOT LIKE 'h%' ESCAPE '#' AS "false";
682 SELECT 'indio' LIKE 'ind_o' ESCAPE '$' AS "true";
688 SELECT 'indio' NOT LIKE 'ind_o' ESCAPE '$' AS "false";
695 -- E061-05 like predicate with escape clause
696 SELECT 'h%' LIKE 'h#%' ESCAPE '#' AS "true";
702 SELECT 'h%' NOT LIKE 'h#%' ESCAPE '#' AS "false";
708 SELECT 'h%wkeye' LIKE 'h#%' ESCAPE '#' AS "false";
714 SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true";
720 SELECT 'h%wkeye' LIKE 'h#%%' ESCAPE '#' AS "true";
726 SELECT 'h%wkeye' NOT LIKE 'h#%%' ESCAPE '#' AS "false";
732 SELECT 'h%awkeye' LIKE 'h#%a%k%e' ESCAPE '#' AS "true";
738 SELECT 'h%awkeye' NOT LIKE 'h#%a%k%e' ESCAPE '#' AS "false";
744 SELECT 'indio' LIKE '_ndio' ESCAPE '$' AS "true";
750 SELECT 'indio' NOT LIKE '_ndio' ESCAPE '$' AS "false";
756 SELECT 'i_dio' LIKE 'i$_d_o' ESCAPE '$' AS "true";
762 SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false";
768 SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false";
774 SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true";
780 SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true";
786 SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false";
792 -- escape character same as pattern character
793 SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true";
799 SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false";
805 SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true";
811 SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false";
817 SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true";
823 SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false";
829 SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true";
835 SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false";
841 SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false";
847 SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true";
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";
863 SELECT 'hawkeye' NOT ILIKE 'h%' AS "false";
869 SELECT 'hawkeye' ILIKE 'H%' AS "true";
875 SELECT 'hawkeye' NOT ILIKE 'H%' AS "false";
881 SELECT 'hawkeye' ILIKE 'H%Eye' AS "true";
887 SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false";
893 SELECT 'Hawkeye' ILIKE 'h%' AS "true";
899 SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false";
906 -- test %/_ combination cases, cf bug #4821
908 SELECT 'foo' LIKE '_%' as t, 'f' LIKE '_%' as t, '' LIKE '_%' as f;
914 SELECT 'foo' LIKE '%_' as t, 'f' LIKE '%_' as t, '' LIKE '%_' as f;
920 SELECT 'foo' LIKE '__%' as t, 'foo' LIKE '___%' as t, 'foo' LIKE '____%' as f;
926 SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f;
933 -- test implicit type conversion
935 -- E021-07 character concatenation
936 SELECT 'unknown' || ' and unknown' AS "Concat unknown types";
938 ----------------------
942 SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";
943 Concat text to unknown type
944 -----------------------------
948 SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";
949 Concat char to unknown type
950 -----------------------------
954 SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";
956 ---------------------
960 SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";
961 Concat text to varchar
962 ------------------------
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;
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;
1004 -- If start plus length is > string length, the result is truncated to
1006 SELECT substr(f1, 99995, 10) from toasttest;
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;
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;
1054 -- If start plus length is > string length, the result is truncated to
1056 SELECT substr(f1, 99995, 10) from toasttest;
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;
1079 SELECT c FROM toasttest;
1081 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1085 DROP TABLE toasttest;
1089 SELECT length('abcdef') AS "length_6";
1098 SELECT strpos('abcdef', 'cd') AS "pos_3";
1104 SELECT strpos('abcdef', 'xy') AS "pos_0";
1113 SELECT replace('abcdef', 'de', '45') AS "abc45f";
1119 SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
1125 SELECT replace('yabadoo', 'bad', '') AS "yaoo";
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";
1142 select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
1148 select split_part('joeuser@mydatabase','@',3) AS "empty string";
1154 select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
1163 select to_hex(256*256*256 - 1) AS "ffffff";
1169 select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
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";
1185 select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1191 select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1197 select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1203 select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1209 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1215 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1221 select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1227 select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1233 select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1239 select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1245 select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1251 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1257 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
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 -----------------------
1274 show standard_conforming_strings;
1275 standard_conforming_strings
1276 -----------------------------
1280 set escape_string_warning = on;
1281 set standard_conforming_strings = on;
1282 show escape_string_warning;
1283 escape_string_warning
1284 -----------------------
1288 show standard_conforming_strings;
1289 standard_conforming_strings
1290 -----------------------------
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 | \\
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,...
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,...
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,...
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\\' ...
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'...
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 ...
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 | \\
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 | \\
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 | \\
1347 -- Additional string functions
1349 SELECT initcap('hi THOMAS');
1355 SELECT lpad('hi', 5, 'xy');
1361 SELECT lpad('hi', 5);
1367 SELECT lpad('hi', -5, 'xy');
1373 SELECT lpad('hello', 2);
1379 SELECT lpad('hi', 5, '');
1385 SELECT rpad('hi', 5, 'xy');
1391 SELECT rpad('hi', 5);
1397 SELECT rpad('hi', -5, 'xy');
1403 SELECT rpad('hello', 2);
1409 SELECT rpad('hi', 5, '');
1415 SELECT ltrim('zzzytrim', 'xyz');
1421 SELECT translate('', '14', 'ax');
1427 SELECT translate('12345', '14', 'ax');
1452 ERROR: null character not permitted
1453 SELECT repeat('Pg', 4);
1459 SELECT repeat('Pg', -4);
1465 SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea);
1471 SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
1477 SELECT btrim(''::bytea, E'\\000'::bytea);
1483 SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);