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 implicit type conversion
908 -- E021-07 character concatenation
909 SELECT 'unknown' || ' and unknown' AS "Concat unknown types";
911 ----------------------
915 SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";
916 Concat text to unknown type
917 -----------------------------
921 SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";
922 Concat char to unknown type
923 -----------------------------
927 SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";
929 ---------------------
933 SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";
934 Concat text to varchar
935 ------------------------
940 -- test substr with toasted text values
942 CREATE TABLE toasttest(f1 text);
943 insert into toasttest values(repeat('1234567890',10000));
944 insert into toasttest values(repeat('1234567890',10000));
946 -- Ensure that some values are uncompressed, to test the faster substring
947 -- operation used in that case
949 alter table toasttest alter column f1 set storage external;
950 insert into toasttest values(repeat('1234567890',10000));
951 insert into toasttest values(repeat('1234567890',10000));
952 -- If the starting position is zero or less, then return from the start of the string
953 -- adjusting the length to be consistent with the "negative start" per SQL92.
954 SELECT substr(f1, -1, 5) from toasttest;
963 -- If the length is less than zero, an ERROR is thrown.
964 SELECT substr(f1, 5, -1) from toasttest;
965 ERROR: negative substring length not allowed
966 -- If no third argument (length) is provided, the length to the end of the
967 -- string is assumed.
968 SELECT substr(f1, 99995) from toasttest;
977 -- If start plus length is > string length, the result is truncated to
979 SELECT substr(f1, 99995, 10) from toasttest;
988 DROP TABLE toasttest;
990 -- test substr with toasted bytea values
992 CREATE TABLE toasttest(f1 bytea);
993 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
994 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
996 -- Ensure that some values are uncompressed, to test the faster substring
997 -- operation used in that case
999 alter table toasttest alter column f1 set storage external;
1000 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1001 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
1002 -- If the starting position is zero or less, then return from the start of the string
1003 -- adjusting the length to be consistent with the "negative start" per SQL92.
1004 SELECT substr(f1, -1, 5) from toasttest;
1013 -- If the length is less than zero, an ERROR is thrown.
1014 SELECT substr(f1, 5, -1) from toasttest;
1015 ERROR: negative substring length not allowed
1016 -- If no third argument (length) is provided, the length to the end of the
1017 -- string is assumed.
1018 SELECT substr(f1, 99995) from toasttest;
1027 -- If start plus length is > string length, the result is truncated to
1029 SELECT substr(f1, 99995, 10) from toasttest;
1038 DROP TABLE toasttest;
1039 -- test internally compressing datums
1040 -- this tests compressing a datum to a very small size which exercises a
1041 -- corner case in packed-varlena handling: even though small, the compressed
1042 -- datum must be given a 4-byte header because there are no bits to indicate
1043 -- compression in a 1-byte header
1044 CREATE TABLE toasttest (c char(4096));
1045 INSERT INTO toasttest VALUES('x');
1046 SELECT length(c), c::text FROM toasttest;
1052 SELECT c FROM toasttest;
1054 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1058 DROP TABLE toasttest;
1062 SELECT length('abcdef') AS "length_6";
1071 SELECT strpos('abcdef', 'cd') AS "pos_3";
1077 SELECT strpos('abcdef', 'xy') AS "pos_0";
1086 SELECT replace('abcdef', 'de', '45') AS "abc45f";
1092 SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
1098 SELECT replace('yabadoo', 'bad', '') AS "yaoo";
1107 select split_part('joeuser@mydatabase','@',0) AS "an error";
1108 ERROR: field position must be greater than zero
1109 select split_part('joeuser@mydatabase','@',1) AS "joeuser";
1115 select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
1121 select split_part('joeuser@mydatabase','@',3) AS "empty string";
1127 select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
1136 select to_hex(256*256*256 - 1) AS "ffffff";
1142 select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
1149 -- MD5 test suite - from IETF RFC 1321
1150 -- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)
1152 select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1158 select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1164 select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1170 select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1176 select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1182 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1188 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1194 select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1200 select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1206 select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1212 select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1218 select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1224 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1230 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1237 -- test behavior of escape_string_warning and standard_conforming_strings options
1239 set escape_string_warning = off;
1240 set standard_conforming_strings = off;
1241 show escape_string_warning;
1242 escape_string_warning
1243 -----------------------
1247 show standard_conforming_strings;
1248 standard_conforming_strings
1249 -----------------------------
1253 set escape_string_warning = on;
1254 set standard_conforming_strings = on;
1255 show escape_string_warning;
1256 escape_string_warning
1257 -----------------------
1261 show standard_conforming_strings;
1262 standard_conforming_strings
1263 -----------------------------
1267 select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
1268 f1 | f2 | f3 | f4 | f5 | f6
1269 -------+--------+---------+-------+--------+----
1270 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1273 set standard_conforming_strings = off;
1274 select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
1275 WARNING: nonstandard use of \\ in a string literal
1276 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1278 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1279 WARNING: nonstandard use of \\ in a string literal
1280 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1282 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1283 WARNING: nonstandard use of \\ in a string literal
1284 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1286 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1287 WARNING: nonstandard use of \\ in a string literal
1288 LINE 1: ...bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' ...
1290 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1291 WARNING: nonstandard use of \\ in a string literal
1292 LINE 1: ...'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd'...
1294 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1295 WARNING: nonstandard use of \\ in a string literal
1296 LINE 1: ...'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as ...
1298 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1299 f1 | f2 | f3 | f4 | f5 | f6
1300 -------+--------+---------+-------+--------+----
1301 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1304 set escape_string_warning = off;
1305 set standard_conforming_strings = on;
1306 select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
1307 f1 | f2 | f3 | f4 | f5 | f6
1308 -------+--------+---------+-------+--------+----
1309 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1312 set standard_conforming_strings = off;
1313 select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
1314 f1 | f2 | f3 | f4 | f5 | f6
1315 -------+--------+---------+-------+--------+----
1316 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1320 -- Additional string functions
1322 SELECT initcap('hi THOMAS');
1328 SELECT lpad('hi', 5, 'xy');
1334 SELECT lpad('hi', 5);
1340 SELECT lpad('hi', -5, 'xy');
1346 SELECT lpad('hello', 2);
1352 SELECT lpad('hi', 5, '');
1358 SELECT rpad('hi', 5, 'xy');
1364 SELECT rpad('hi', 5);
1370 SELECT rpad('hi', -5, 'xy');
1376 SELECT rpad('hello', 2);
1382 SELECT rpad('hi', 5, '');
1388 SELECT ltrim('zzzytrim', 'xyz');
1394 SELECT translate('', '14', 'ax');
1400 SELECT translate('12345', '14', 'ax');
1425 ERROR: null character not permitted
1426 SELECT repeat('Pg', 4);
1432 SELECT repeat('Pg', -4);
1438 SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea);
1444 SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
1450 SELECT btrim(''::bytea, E'\\000'::bytea);
1456 SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);