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 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
66 SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
67 ERROR: unsafe use of string constant with Unicode escapes
68 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
69 SELECT U&' \' UESCAPE '!' AS "tricky";
70 ERROR: unsafe use of string constant with Unicode escapes
71 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
72 SELECT 'tricky' AS U&"\" UESCAPE '!';
78 SELECT U&'wrong: \061';
79 ERROR: unsafe use of string constant with Unicode escapes
80 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
81 SELECT U&'wrong: \+0061';
82 ERROR: unsafe use of string constant with Unicode escapes
83 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
84 SELECT U&'wrong: +0061' UESCAPE '+';
85 ERROR: unsafe use of string constant with Unicode escapes
86 DETAIL: String constants with Unicode escapes cannot be used when standard_conforming_strings is off.
87 RESET standard_conforming_strings;
89 -- test conversions between various string types
90 -- E021-10 implicit casting among the character data types
92 SELECT CAST(f1 AS text) AS "text(char)" FROM CHAR_TBL;
101 SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL;
110 SELECT CAST(name 'namefield' AS text) AS "text(name)";
116 -- since this is an explicit cast, it should truncate w/o error:
117 SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL;
124 -- note: implicit-cast case is tested in char.sql
125 SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL;
127 ----------------------
132 SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL;
141 SELECT CAST(name 'namefield' AS char(10)) AS "char(name)";
147 SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL;
154 SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL;
163 SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)";
170 -- test SQL92 string functions
171 -- E### and T### are feature reference numbers from SQL99
173 -- E021-09 trim function
174 SELECT TRIM(BOTH FROM ' bunch o blanks ') = 'bunch o blanks' AS "bunch o blanks";
180 SELECT TRIM(LEADING FROM ' bunch o blanks ') = 'bunch o blanks ' AS "bunch o blanks ";
186 SELECT TRIM(TRAILING FROM ' bunch o blanks ') = ' bunch o blanks' AS " bunch o blanks";
192 SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs";
198 -- E021-06 substring expression
199 SELECT SUBSTRING('1234567890' FROM 3) = '34567890' AS "34567890";
205 SELECT SUBSTRING('1234567890' FROM 4 FOR 3) = '456' AS "456";
211 -- T581 regular expression substring (with SQL99's bizarre regexp syntax)
212 SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd";
218 -- No match should return NULL
219 SELECT SUBSTRING('abcdefg' FROM '#"(b_d)#"%' FOR '#') IS NULL AS "True";
225 -- Null inputs should return NULL
226 SELECT SUBSTRING('abcdefg' FROM '(b|c)' FOR NULL) IS NULL AS "True";
232 SELECT SUBSTRING(NULL FROM '(b|c)' FOR '#') IS NULL AS "True";
238 SELECT SUBSTRING('abcdefg' FROM NULL FOR '#') IS NULL AS "True";
244 -- PostgreSQL extension to allow omitting the escape character;
245 -- here the regexp is taken as Posix syntax
246 SELECT SUBSTRING('abcdefg' FROM 'c.e') AS "cde";
252 -- With a parenthesized subexpression, return only what matches the subexpr
253 SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde";
259 -- PostgreSQL extension to allow using back reference in replace string;
260 SELECT regexp_replace('1112223333', E'(\\d{3})(\\d{3})(\\d{4})', E'(\\1) \\2-\\3');
266 SELECT regexp_replace('AAA BBB CCC ', E'\\s+', ' ', 'g');
272 SELECT regexp_replace('AAA', '^|$', 'Z', 'g');
278 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi');
284 -- invalid regexp option
285 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'z');
286 ERROR: invalid regexp option: "z"
287 -- set so we can tell NULL from empty string
289 -- return all matches from regexp
290 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$);
296 -- test case insensitive
297 SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i');
303 -- global option - more than one match
304 SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g');
311 -- empty capture group (matched empty string)
312 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$);
319 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$);
324 -- optional capture group did not match, null entry in array
325 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$);
332 SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$);
339 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$, 'gz');
340 ERROR: invalid regexp option: "z"
341 SELECT regexp_matches('foobarbequebaz', $re$(barbeque$re$);
342 ERROR: invalid regular expression: parentheses () not balanced
343 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque){2,1}$re$);
344 ERROR: invalid regular expression: invalid repetition count(s)
345 -- split string on regexp
346 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', $re$\s+$re$) AS foo;
360 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', $re$\s+$re$);
361 regexp_split_to_array
362 ------------------------------------------------
363 {the,quick,brown,fox,jumped,over,the,lazy,dog}
366 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', $re$\s*$re$) AS foo;
407 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', $re$\s*$re$);
408 regexp_split_to_array
409 ---------------------------------------------------------------------------
410 {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}
413 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', '') AS foo;
462 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', '');
463 regexp_split_to_array
464 -----------------------------------------------------------------------------------------------------------
465 {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}
469 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'i') AS foo;
471 -----------------------+--------
473 QUick bROWn FOx jUMP | 21
479 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'i');
480 regexp_split_to_array
481 --------------------------------------------------------
482 {th," QUick bROWn FOx jUMP","d ov","r TH"," lazy dOG"}
485 -- no match of pattern
486 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', 'nomatch') AS foo;
488 ----------------------------------------------+--------
489 the quick brown fox jumped over the lazy dog | 44
492 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', 'nomatch');
493 regexp_split_to_array
494 --------------------------------------------------
495 {"the quick brown fox jumped over the lazy dog"}
499 SELECT regexp_split_to_array('123456','1');
500 regexp_split_to_array
501 -----------------------
505 SELECT regexp_split_to_array('123456','6');
506 regexp_split_to_array
507 -----------------------
511 SELECT regexp_split_to_array('123456','.');
512 regexp_split_to_array
513 ------------------------
514 {"","","","","","",""}
518 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'zippy') AS foo;
519 ERROR: invalid regexp option: "z"
520 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'iz');
521 ERROR: invalid regexp option: "z"
522 -- global option meaningless for regexp_split
523 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'g') AS foo;
524 ERROR: regexp_split does not support the global option
525 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'g');
526 ERROR: regexp_split does not support the global option
527 -- change NULL-display back
529 -- E021-11 position expression
530 SELECT POSITION('4' IN '1234567890') = '4' AS "4";
536 SELECT POSITION('5' IN '1234567890') = '5' AS "5";
542 -- T312 character overlay function
543 SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
549 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5) AS "yabadaba";
555 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5 FOR 0) AS "yabadabadoo";
561 SELECT OVERLAY('babosa' PLACING 'ubb' FROM 2 FOR 4) AS "bubba";
569 -- Be sure to form every test as a LIKE/NOT LIKE pair.
572 -- E061-04 like predicate
573 SELECT 'hawkeye' LIKE 'h%' AS "true";
579 SELECT 'hawkeye' NOT LIKE 'h%' AS "false";
585 SELECT 'hawkeye' LIKE 'H%' AS "false";
591 SELECT 'hawkeye' NOT LIKE 'H%' AS "true";
597 SELECT 'hawkeye' LIKE 'indio%' AS "false";
603 SELECT 'hawkeye' NOT LIKE 'indio%' AS "true";
609 SELECT 'hawkeye' LIKE 'h%eye' AS "true";
615 SELECT 'hawkeye' NOT LIKE 'h%eye' AS "false";
621 SELECT 'indio' LIKE '_ndio' AS "true";
627 SELECT 'indio' NOT LIKE '_ndio' AS "false";
633 SELECT 'indio' LIKE 'in__o' AS "true";
639 SELECT 'indio' NOT LIKE 'in__o' AS "false";
645 SELECT 'indio' LIKE 'in_o' AS "false";
651 SELECT 'indio' NOT LIKE 'in_o' AS "true";
657 -- unused escape character
658 SELECT 'hawkeye' LIKE 'h%' ESCAPE '#' AS "true";
664 SELECT 'hawkeye' NOT LIKE 'h%' ESCAPE '#' AS "false";
670 SELECT 'indio' LIKE 'ind_o' ESCAPE '$' AS "true";
676 SELECT 'indio' NOT LIKE 'ind_o' ESCAPE '$' AS "false";
683 -- E061-05 like predicate with escape clause
684 SELECT 'h%' LIKE 'h#%' ESCAPE '#' AS "true";
690 SELECT 'h%' NOT LIKE 'h#%' ESCAPE '#' AS "false";
696 SELECT 'h%wkeye' LIKE 'h#%' ESCAPE '#' AS "false";
702 SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true";
708 SELECT 'h%wkeye' LIKE 'h#%%' ESCAPE '#' AS "true";
714 SELECT 'h%wkeye' NOT LIKE 'h#%%' ESCAPE '#' AS "false";
720 SELECT 'h%awkeye' LIKE 'h#%a%k%e' ESCAPE '#' AS "true";
726 SELECT 'h%awkeye' NOT LIKE 'h#%a%k%e' ESCAPE '#' AS "false";
732 SELECT 'indio' LIKE '_ndio' ESCAPE '$' AS "true";
738 SELECT 'indio' NOT LIKE '_ndio' ESCAPE '$' AS "false";
744 SELECT 'i_dio' LIKE 'i$_d_o' ESCAPE '$' AS "true";
750 SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false";
756 SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false";
762 SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true";
768 SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true";
774 SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false";
780 -- escape character same as pattern character
781 SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true";
787 SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false";
793 SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true";
799 SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false";
805 SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true";
811 SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false";
817 SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true";
823 SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false";
829 SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false";
835 SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true";
842 -- test ILIKE (case-insensitive LIKE)
843 -- Be sure to form every test as an ILIKE/NOT ILIKE pair.
845 SELECT 'hawkeye' ILIKE 'h%' AS "true";
851 SELECT 'hawkeye' NOT ILIKE 'h%' AS "false";
857 SELECT 'hawkeye' ILIKE 'H%' AS "true";
863 SELECT 'hawkeye' NOT ILIKE 'H%' AS "false";
869 SELECT 'hawkeye' ILIKE 'H%Eye' AS "true";
875 SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false";
881 SELECT 'Hawkeye' ILIKE 'h%' AS "true";
887 SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false";
894 -- test implicit type conversion
896 -- E021-07 character concatenation
897 SELECT 'unknown' || ' and unknown' AS "Concat unknown types";
899 ----------------------
903 SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";
904 Concat text to unknown type
905 -----------------------------
909 SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";
910 Concat char to unknown type
911 -----------------------------
915 SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";
917 ---------------------
921 SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";
922 Concat text to varchar
923 ------------------------
928 -- test substr with toasted text values
930 CREATE TABLE toasttest(f1 text);
931 insert into toasttest values(repeat('1234567890',10000));
932 insert into toasttest values(repeat('1234567890',10000));
934 -- Ensure that some values are uncompressed, to test the faster substring
935 -- operation used in that case
937 alter table toasttest alter column f1 set storage external;
938 insert into toasttest values(repeat('1234567890',10000));
939 insert into toasttest values(repeat('1234567890',10000));
940 -- If the starting position is zero or less, then return from the start of the string
941 -- adjusting the length to be consistent with the "negative start" per SQL92.
942 SELECT substr(f1, -1, 5) from toasttest;
951 -- If the length is less than zero, an ERROR is thrown.
952 SELECT substr(f1, 5, -1) from toasttest;
953 ERROR: negative substring length not allowed
954 -- If no third argument (length) is provided, the length to the end of the
955 -- string is assumed.
956 SELECT substr(f1, 99995) from toasttest;
965 -- If start plus length is > string length, the result is truncated to
967 SELECT substr(f1, 99995, 10) from toasttest;
976 DROP TABLE toasttest;
978 -- test substr with toasted bytea values
980 CREATE TABLE toasttest(f1 bytea);
981 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
982 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
984 -- Ensure that some values are uncompressed, to test the faster substring
985 -- operation used in that case
987 alter table toasttest alter column f1 set storage external;
988 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
989 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
990 -- If the starting position is zero or less, then return from the start of the string
991 -- adjusting the length to be consistent with the "negative start" per SQL92.
992 SELECT substr(f1, -1, 5) from toasttest;
1001 -- If the length is less than zero, an ERROR is thrown.
1002 SELECT substr(f1, 5, -1) from toasttest;
1003 ERROR: negative substring length not allowed
1004 -- If no third argument (length) is provided, the length to the end of the
1005 -- string is assumed.
1006 SELECT substr(f1, 99995) from toasttest;
1015 -- If start plus length is > string length, the result is truncated to
1017 SELECT substr(f1, 99995, 10) from toasttest;
1026 DROP TABLE toasttest;
1027 -- test internally compressing datums
1028 -- this tests compressing a datum to a very small size which exercises a
1029 -- corner case in packed-varlena handling: even though small, the compressed
1030 -- datum must be given a 4-byte header because there are no bits to indicate
1031 -- compression in a 1-byte header
1032 CREATE TABLE toasttest (c char(4096));
1033 INSERT INTO toasttest VALUES('x');
1034 SELECT length(c), c::text FROM toasttest;
1040 SELECT c FROM toasttest;
1042 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1046 DROP TABLE toasttest;
1050 SELECT length('abcdef') AS "length_6";
1059 SELECT strpos('abcdef', 'cd') AS "pos_3";
1065 SELECT strpos('abcdef', 'xy') AS "pos_0";
1074 SELECT replace('abcdef', 'de', '45') AS "abc45f";
1080 SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
1086 SELECT replace('yabadoo', 'bad', '') AS "yaoo";
1095 select split_part('joeuser@mydatabase','@',0) AS "an error";
1096 ERROR: field position must be greater than zero
1097 select split_part('joeuser@mydatabase','@',1) AS "joeuser";
1103 select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
1109 select split_part('joeuser@mydatabase','@',3) AS "empty string";
1115 select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
1124 select to_hex(256*256*256 - 1) AS "ffffff";
1130 select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
1137 -- MD5 test suite - from IETF RFC 1321
1138 -- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)
1140 select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1146 select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1152 select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1158 select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1164 select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1170 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1176 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1182 select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1188 select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1194 select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1200 select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1206 select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1212 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1218 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1225 -- test behavior of escape_string_warning and standard_conforming_strings options
1227 set escape_string_warning = off;
1228 set standard_conforming_strings = off;
1229 show escape_string_warning;
1230 escape_string_warning
1231 -----------------------
1235 show standard_conforming_strings;
1236 standard_conforming_strings
1237 -----------------------------
1241 set escape_string_warning = on;
1242 set standard_conforming_strings = on;
1243 show escape_string_warning;
1244 escape_string_warning
1245 -----------------------
1249 show standard_conforming_strings;
1250 standard_conforming_strings
1251 -----------------------------
1255 select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
1256 f1 | f2 | f3 | f4 | f5 | f6
1257 -------+--------+---------+-------+--------+----
1258 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1261 set standard_conforming_strings = off;
1262 select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
1263 WARNING: nonstandard use of \\ in a string literal
1264 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1266 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1267 WARNING: nonstandard use of \\ in a string literal
1268 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1270 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1271 WARNING: nonstandard use of \\ in a string literal
1272 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1274 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1275 WARNING: nonstandard use of \\ in a string literal
1276 LINE 1: ...bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' ...
1278 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1279 WARNING: nonstandard use of \\ in a string literal
1280 LINE 1: ...'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd'...
1282 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1283 WARNING: nonstandard use of \\ in a string literal
1284 LINE 1: ...'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as ...
1286 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1287 f1 | f2 | f3 | f4 | f5 | f6
1288 -------+--------+---------+-------+--------+----
1289 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1292 set escape_string_warning = off;
1293 set standard_conforming_strings = on;
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 f1 | f2 | f3 | f4 | f5 | f6
1303 -------+--------+---------+-------+--------+----
1304 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1308 -- Additional string functions
1310 SELECT initcap('hi THOMAS');
1316 SELECT lpad('hi', 5, 'xy');
1322 SELECT lpad('hi', 5);
1328 SELECT lpad('hi', -5, 'xy');
1334 SELECT lpad('hello', 2);
1340 SELECT lpad('hi', 5, '');
1346 SELECT rpad('hi', 5, 'xy');
1352 SELECT rpad('hi', 5);
1358 SELECT rpad('hi', -5, 'xy');
1364 SELECT rpad('hello', 2);
1370 SELECT rpad('hi', 5, '');
1376 SELECT ltrim('zzzytrim', 'xyz');
1382 SELECT translate('', '14', 'ax');
1388 SELECT translate('12345', '14', 'ax');
1413 ERROR: null character not permitted
1414 SELECT repeat('Pg', 4);
1420 SELECT repeat('Pg', -4);
1426 SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea);
1432 SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
1438 SELECT btrim(''::bytea, E'\\000'::bytea);
1444 SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);