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 SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
31 SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
37 SELECT U&'wrong: \061';
38 ERROR: invalid Unicode escape value at or near "\061'"
39 LINE 1: SELECT U&'wrong: \061';
41 SELECT U&'wrong: \+0061';
42 ERROR: invalid Unicode escape value at or near "\+0061'"
43 LINE 1: SELECT U&'wrong: \+0061';
45 SELECT U&'wrong: +0061' UESCAPE '+';
46 ERROR: invalid Unicode escape character at or near "+'"
47 LINE 1: SELECT U&'wrong: +0061' UESCAPE '+';
50 -- test conversions between various string types
51 -- E021-10 implicit casting among the character data types
53 SELECT CAST(f1 AS text) AS "text(char)" FROM CHAR_TBL;
62 SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL;
71 SELECT CAST(name 'namefield' AS text) AS "text(name)";
77 -- since this is an explicit cast, it should truncate w/o error:
78 SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL;
85 -- note: implicit-cast case is tested in char.sql
86 SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL;
88 ----------------------
93 SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL;
102 SELECT CAST(name 'namefield' AS char(10)) AS "char(name)";
108 SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL;
115 SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL;
124 SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)";
131 -- test SQL92 string functions
132 -- E### and T### are feature reference numbers from SQL99
134 -- E021-09 trim function
135 SELECT TRIM(BOTH FROM ' bunch o blanks ') = 'bunch o blanks' AS "bunch o blanks";
141 SELECT TRIM(LEADING FROM ' bunch o blanks ') = 'bunch o blanks ' AS "bunch o blanks ";
147 SELECT TRIM(TRAILING FROM ' bunch o blanks ') = ' bunch o blanks' AS " bunch o blanks";
153 SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs";
159 -- E021-06 substring expression
160 SELECT SUBSTRING('1234567890' FROM 3) = '34567890' AS "34567890";
166 SELECT SUBSTRING('1234567890' FROM 4 FOR 3) = '456' AS "456";
172 -- T581 regular expression substring (with SQL99's bizarre regexp syntax)
173 SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd";
179 -- No match should return NULL
180 SELECT SUBSTRING('abcdefg' FROM '#"(b_d)#"%' FOR '#') IS NULL AS "True";
186 -- Null inputs should return NULL
187 SELECT SUBSTRING('abcdefg' FROM '(b|c)' FOR NULL) IS NULL AS "True";
193 SELECT SUBSTRING(NULL FROM '(b|c)' FOR '#') IS NULL AS "True";
199 SELECT SUBSTRING('abcdefg' FROM NULL FOR '#') IS NULL AS "True";
205 -- PostgreSQL extension to allow omitting the escape character;
206 -- here the regexp is taken as Posix syntax
207 SELECT SUBSTRING('abcdefg' FROM 'c.e') AS "cde";
213 -- With a parenthesized subexpression, return only what matches the subexpr
214 SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde";
220 -- PostgreSQL extension to allow using back reference in replace string;
221 SELECT regexp_replace('1112223333', E'(\\d{3})(\\d{3})(\\d{4})', E'(\\1) \\2-\\3');
227 SELECT regexp_replace('AAA BBB CCC ', E'\\s+', ' ', 'g');
233 SELECT regexp_replace('AAA', '^|$', 'Z', 'g');
239 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi');
245 -- invalid regexp option
246 SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'z');
247 ERROR: invalid regexp option: "z"
248 -- set so we can tell NULL from empty string
250 -- return all matches from regexp
251 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$);
257 -- test case insensitive
258 SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i');
264 -- global option - more than one match
265 SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g');
272 -- empty capture group (matched empty string)
273 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$);
280 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$);
285 -- optional capture group did not match, null entry in array
286 SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$);
293 SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$);
300 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$, 'gz');
301 ERROR: invalid regexp option: "z"
302 SELECT regexp_matches('foobarbequebaz', $re$(barbeque$re$);
303 ERROR: invalid regular expression: parentheses () not balanced
304 SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque){2,1}$re$);
305 ERROR: invalid regular expression: invalid repetition count(s)
306 -- split string on regexp
307 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', $re$\s+$re$) AS foo;
321 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', $re$\s+$re$);
322 regexp_split_to_array
323 ------------------------------------------------
324 {the,quick,brown,fox,jumped,over,the,lazy,dog}
327 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', $re$\s*$re$) AS foo;
368 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', $re$\s*$re$);
369 regexp_split_to_array
370 ---------------------------------------------------------------------------
371 {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}
374 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', '') AS foo;
423 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', '');
424 regexp_split_to_array
425 -----------------------------------------------------------------------------------------------------------
426 {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}
430 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'i') AS foo;
432 -----------------------+--------
434 QUick bROWn FOx jUMP | 21
440 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'i');
441 regexp_split_to_array
442 --------------------------------------------------------
443 {th," QUick bROWn FOx jUMP","d ov","r TH"," lazy dOG"}
446 -- no match of pattern
447 SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumped over the lazy dog', 'nomatch') AS foo;
449 ----------------------------------------------+--------
450 the quick brown fox jumped over the lazy dog | 44
453 SELECT regexp_split_to_array('the quick brown fox jumped over the lazy dog', 'nomatch');
454 regexp_split_to_array
455 --------------------------------------------------
456 {"the quick brown fox jumped over the lazy dog"}
460 SELECT regexp_split_to_array('123456','1');
461 regexp_split_to_array
462 -----------------------
466 SELECT regexp_split_to_array('123456','6');
467 regexp_split_to_array
468 -----------------------
472 SELECT regexp_split_to_array('123456','.');
473 regexp_split_to_array
474 ------------------------
475 {"","","","","","",""}
479 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'zippy') AS foo;
480 ERROR: invalid regexp option: "z"
481 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'iz');
482 ERROR: invalid regexp option: "z"
483 -- global option meaningless for regexp_split
484 SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'g') AS foo;
485 ERROR: regexp_split does not support the global option
486 SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPed ovEr THE lazy dOG', 'e', 'g');
487 ERROR: regexp_split does not support the global option
488 -- change NULL-display back
490 -- E021-11 position expression
491 SELECT POSITION('4' IN '1234567890') = '4' AS "4";
497 SELECT POSITION('5' IN '1234567890') = '5' AS "5";
503 -- T312 character overlay function
504 SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
510 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5) AS "yabadaba";
516 SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5 FOR 0) AS "yabadabadoo";
522 SELECT OVERLAY('babosa' PLACING 'ubb' FROM 2 FOR 4) AS "bubba";
530 -- Be sure to form every test as a LIKE/NOT LIKE pair.
533 -- E061-04 like predicate
534 SELECT 'hawkeye' LIKE 'h%' AS "true";
540 SELECT 'hawkeye' NOT LIKE 'h%' AS "false";
546 SELECT 'hawkeye' LIKE 'H%' AS "false";
552 SELECT 'hawkeye' NOT LIKE 'H%' AS "true";
558 SELECT 'hawkeye' LIKE 'indio%' AS "false";
564 SELECT 'hawkeye' NOT LIKE 'indio%' AS "true";
570 SELECT 'hawkeye' LIKE 'h%eye' AS "true";
576 SELECT 'hawkeye' NOT LIKE 'h%eye' AS "false";
582 SELECT 'indio' LIKE '_ndio' AS "true";
588 SELECT 'indio' NOT LIKE '_ndio' AS "false";
594 SELECT 'indio' LIKE 'in__o' AS "true";
600 SELECT 'indio' NOT LIKE 'in__o' AS "false";
606 SELECT 'indio' LIKE 'in_o' AS "false";
612 SELECT 'indio' NOT LIKE 'in_o' AS "true";
618 -- unused escape character
619 SELECT 'hawkeye' LIKE 'h%' ESCAPE '#' AS "true";
625 SELECT 'hawkeye' NOT LIKE 'h%' ESCAPE '#' AS "false";
631 SELECT 'indio' LIKE 'ind_o' ESCAPE '$' AS "true";
637 SELECT 'indio' NOT LIKE 'ind_o' ESCAPE '$' AS "false";
644 -- E061-05 like predicate with escape clause
645 SELECT 'h%' LIKE 'h#%' ESCAPE '#' AS "true";
651 SELECT 'h%' NOT LIKE 'h#%' ESCAPE '#' AS "false";
657 SELECT 'h%wkeye' LIKE 'h#%' ESCAPE '#' AS "false";
663 SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true";
669 SELECT 'h%wkeye' LIKE 'h#%%' ESCAPE '#' AS "true";
675 SELECT 'h%wkeye' NOT LIKE 'h#%%' ESCAPE '#' AS "false";
681 SELECT 'h%awkeye' LIKE 'h#%a%k%e' ESCAPE '#' AS "true";
687 SELECT 'h%awkeye' NOT LIKE 'h#%a%k%e' ESCAPE '#' AS "false";
693 SELECT 'indio' LIKE '_ndio' ESCAPE '$' AS "true";
699 SELECT 'indio' NOT LIKE '_ndio' ESCAPE '$' AS "false";
705 SELECT 'i_dio' LIKE 'i$_d_o' ESCAPE '$' AS "true";
711 SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false";
717 SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false";
723 SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true";
729 SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true";
735 SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false";
741 -- escape character same as pattern character
742 SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true";
748 SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false";
754 SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true";
760 SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false";
766 SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true";
772 SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false";
778 SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true";
784 SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false";
790 SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false";
796 SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true";
803 -- test ILIKE (case-insensitive LIKE)
804 -- Be sure to form every test as an ILIKE/NOT ILIKE pair.
806 SELECT 'hawkeye' ILIKE 'h%' AS "true";
812 SELECT 'hawkeye' NOT ILIKE 'h%' AS "false";
818 SELECT 'hawkeye' ILIKE 'H%' AS "true";
824 SELECT 'hawkeye' NOT ILIKE 'H%' AS "false";
830 SELECT 'hawkeye' ILIKE 'H%Eye' AS "true";
836 SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false";
842 SELECT 'Hawkeye' ILIKE 'h%' AS "true";
848 SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false";
855 -- test implicit type conversion
857 -- E021-07 character concatenation
858 SELECT 'unknown' || ' and unknown' AS "Concat unknown types";
860 ----------------------
864 SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";
865 Concat text to unknown type
866 -----------------------------
870 SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";
871 Concat char to unknown type
872 -----------------------------
876 SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";
878 ---------------------
882 SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";
883 Concat text to varchar
884 ------------------------
889 -- test substr with toasted text values
891 CREATE TABLE toasttest(f1 text);
892 insert into toasttest values(repeat('1234567890',10000));
893 insert into toasttest values(repeat('1234567890',10000));
895 -- Ensure that some values are uncompressed, to test the faster substring
896 -- operation used in that case
898 alter table toasttest alter column f1 set storage external;
899 insert into toasttest values(repeat('1234567890',10000));
900 insert into toasttest values(repeat('1234567890',10000));
901 -- If the starting position is zero or less, then return from the start of the string
902 -- adjusting the length to be consistent with the "negative start" per SQL92.
903 SELECT substr(f1, -1, 5) from toasttest;
912 -- If the length is less than zero, an ERROR is thrown.
913 SELECT substr(f1, 5, -1) from toasttest;
914 ERROR: negative substring length not allowed
915 -- If no third argument (length) is provided, the length to the end of the
916 -- string is assumed.
917 SELECT substr(f1, 99995) from toasttest;
926 -- If start plus length is > string length, the result is truncated to
928 SELECT substr(f1, 99995, 10) from toasttest;
937 DROP TABLE toasttest;
939 -- test substr with toasted bytea values
941 CREATE TABLE toasttest(f1 bytea);
942 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
943 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
945 -- Ensure that some values are uncompressed, to test the faster substring
946 -- operation used in that case
948 alter table toasttest alter column f1 set storage external;
949 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
950 insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
951 -- If the starting position is zero or less, then return from the start of the string
952 -- adjusting the length to be consistent with the "negative start" per SQL92.
953 SELECT substr(f1, -1, 5) from toasttest;
962 -- If the length is less than zero, an ERROR is thrown.
963 SELECT substr(f1, 5, -1) from toasttest;
964 ERROR: negative substring length not allowed
965 -- If no third argument (length) is provided, the length to the end of the
966 -- string is assumed.
967 SELECT substr(f1, 99995) from toasttest;
976 -- If start plus length is > string length, the result is truncated to
978 SELECT substr(f1, 99995, 10) from toasttest;
987 DROP TABLE toasttest;
988 -- test internally compressing datums
989 -- this tests compressing a datum to a very small size which exercises a
990 -- corner case in packed-varlena handling: even though small, the compressed
991 -- datum must be given a 4-byte header because there are no bits to indicate
992 -- compression in a 1-byte header
993 CREATE TABLE toasttest (c char(4096));
994 INSERT INTO toasttest VALUES('x');
995 SELECT length(c), c::text FROM toasttest;
1001 SELECT c FROM toasttest;
1003 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1007 DROP TABLE toasttest;
1011 SELECT length('abcdef') AS "length_6";
1020 SELECT strpos('abcdef', 'cd') AS "pos_3";
1026 SELECT strpos('abcdef', 'xy') AS "pos_0";
1035 SELECT replace('abcdef', 'de', '45') AS "abc45f";
1041 SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
1047 SELECT replace('yabadoo', 'bad', '') AS "yaoo";
1056 select split_part('joeuser@mydatabase','@',0) AS "an error";
1057 ERROR: field position must be greater than zero
1058 select split_part('joeuser@mydatabase','@',1) AS "joeuser";
1064 select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
1070 select split_part('joeuser@mydatabase','@',3) AS "empty string";
1076 select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
1085 select to_hex(256*256*256 - 1) AS "ffffff";
1091 select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
1098 -- MD5 test suite - from IETF RFC 1321
1099 -- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)
1101 select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1107 select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1113 select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1119 select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1125 select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1131 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1137 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1143 select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
1149 select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
1155 select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
1161 select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
1167 select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
1173 select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
1179 select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
1186 -- test behavior of escape_string_warning and standard_conforming_strings options
1188 set escape_string_warning = off;
1189 set standard_conforming_strings = off;
1190 show escape_string_warning;
1191 escape_string_warning
1192 -----------------------
1196 show standard_conforming_strings;
1197 standard_conforming_strings
1198 -----------------------------
1202 set escape_string_warning = on;
1203 set standard_conforming_strings = on;
1204 show escape_string_warning;
1205 escape_string_warning
1206 -----------------------
1210 show standard_conforming_strings;
1211 standard_conforming_strings
1212 -----------------------------
1216 select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
1217 f1 | f2 | f3 | f4 | f5 | f6
1218 -------+--------+---------+-------+--------+----
1219 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1222 set standard_conforming_strings = off;
1223 select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
1224 WARNING: nonstandard use of \\ in a string literal
1225 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1227 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1228 WARNING: nonstandard use of \\ in a string literal
1229 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1231 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1232 WARNING: nonstandard use of \\ in a string literal
1233 LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
1235 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1236 WARNING: nonstandard use of \\ in a string literal
1237 LINE 1: ...bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' ...
1239 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1240 WARNING: nonstandard use of \\ in a string literal
1241 LINE 1: ...'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd'...
1243 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1244 WARNING: nonstandard use of \\ in a string literal
1245 LINE 1: ...'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as ...
1247 HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
1248 f1 | f2 | f3 | f4 | f5 | f6
1249 -------+--------+---------+-------+--------+----
1250 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1253 set escape_string_warning = off;
1254 set standard_conforming_strings = on;
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 f1 | f2 | f3 | f4 | f5 | f6
1264 -------+--------+---------+-------+--------+----
1265 a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\
1269 -- Additional string functions
1271 SELECT initcap('hi THOMAS');
1277 SELECT lpad('hi', 5, 'xy');
1283 SELECT lpad('hi', 5);
1289 SELECT lpad('hi', -5, 'xy');
1295 SELECT lpad('hello', 2);
1301 SELECT lpad('hi', 5, '');
1307 SELECT rpad('hi', 5, 'xy');
1313 SELECT rpad('hi', 5);
1319 SELECT rpad('hi', -5, 'xy');
1325 SELECT rpad('hello', 2);
1331 SELECT rpad('hi', 5, '');
1337 SELECT ltrim('zzzytrim', 'xyz');
1343 SELECT translate('', '14', 'ax');
1349 SELECT translate('12345', '14', 'ax');
1374 ERROR: null character not permitted
1375 SELECT repeat('Pg', 4);
1381 SELECT repeat('Pg', -4);
1387 SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea);
1393 SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
1399 SELECT btrim(''::bytea, E'\\000'::bytea);
1405 SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);