1-- 2-- STRINGS 3-- Test various data entry syntaxes. 4-- 5 6-- SQL string continuation syntax 7-- E021-03 character string literals 8SELECT 'first line' 9' - next line' 10 ' - third line' 11 AS "Three lines to one"; 12 13-- illegal string continuation syntax 14SELECT 'first line' 15' - next line' /* this comment is not allowed here */ 16' - third line' 17 AS "Illegal comment within continuation"; 18 19-- Unicode escapes 20SET standard_conforming_strings TO on; 21 22SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061"; 23SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*'; 24 25SELECT U&' \' UESCAPE '!' AS "tricky"; 26SELECT 'tricky' AS U&"\" UESCAPE '!'; 27 28SELECT U&'wrong: \061'; 29SELECT U&'wrong: \+0061'; 30SELECT U&'wrong: +0061' UESCAPE '+'; 31 32SET standard_conforming_strings TO off; 33 34SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061"; 35SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*'; 36 37SELECT U&' \' UESCAPE '!' AS "tricky"; 38SELECT 'tricky' AS U&"\" UESCAPE '!'; 39 40SELECT U&'wrong: \061'; 41SELECT U&'wrong: \+0061'; 42SELECT U&'wrong: +0061' UESCAPE '+'; 43 44RESET standard_conforming_strings; 45 46-- bytea 47SET bytea_output TO hex; 48SELECT E'\\xDeAdBeEf'::bytea; 49SELECT E'\\x De Ad Be Ef '::bytea; 50SELECT E'\\xDeAdBeE'::bytea; 51SELECT E'\\xDeAdBeEx'::bytea; 52SELECT E'\\xDe00BeEf'::bytea; 53SELECT E'DeAdBeEf'::bytea; 54SELECT E'De\\000dBeEf'::bytea; 55SELECT E'De\123dBeEf'::bytea; 56SELECT E'De\\123dBeEf'::bytea; 57SELECT E'De\\678dBeEf'::bytea; 58 59SET bytea_output TO escape; 60SELECT E'\\xDeAdBeEf'::bytea; 61SELECT E'\\x De Ad Be Ef '::bytea; 62SELECT E'\\xDe00BeEf'::bytea; 63SELECT E'DeAdBeEf'::bytea; 64SELECT E'De\\000dBeEf'::bytea; 65SELECT E'De\\123dBeEf'::bytea; 66 67-- 68-- test conversions between various string types 69-- E021-10 implicit casting among the character data types 70-- 71 72SELECT CAST(f1 AS text) AS "text(char)" FROM CHAR_TBL; 73 74SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL; 75 76SELECT CAST(name 'namefield' AS text) AS "text(name)"; 77 78-- since this is an explicit cast, it should truncate w/o error: 79SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL; 80-- note: implicit-cast case is tested in char.sql 81 82SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL; 83 84SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL; 85 86SELECT CAST(name 'namefield' AS char(10)) AS "char(name)"; 87 88SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL; 89 90SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL; 91 92SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)"; 93 94-- 95-- test SQL string functions 96-- E### and T### are feature reference numbers from SQL99 97-- 98 99-- E021-09 trim function 100SELECT TRIM(BOTH FROM ' bunch o blanks ') = 'bunch o blanks' AS "bunch o blanks"; 101 102SELECT TRIM(LEADING FROM ' bunch o blanks ') = 'bunch o blanks ' AS "bunch o blanks "; 103 104SELECT TRIM(TRAILING FROM ' bunch o blanks ') = ' bunch o blanks' AS " bunch o blanks"; 105 106SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs"; 107 108-- E021-06 substring expression 109SELECT SUBSTRING('1234567890' FROM 3) = '34567890' AS "34567890"; 110 111SELECT SUBSTRING('1234567890' FROM 4 FOR 3) = '456' AS "456"; 112 113-- T581 regular expression substring (with SQL99's bizarre regexp syntax) 114SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd"; 115 116-- No match should return NULL 117SELECT SUBSTRING('abcdefg' FROM '#"(b_d)#"%' FOR '#') IS NULL AS "True"; 118 119-- Null inputs should return NULL 120SELECT SUBSTRING('abcdefg' FROM '(b|c)' FOR NULL) IS NULL AS "True"; 121SELECT SUBSTRING(NULL FROM '(b|c)' FOR '#') IS NULL AS "True"; 122SELECT SUBSTRING('abcdefg' FROM NULL FOR '#') IS NULL AS "True"; 123 124-- PostgreSQL extension to allow omitting the escape character; 125-- here the regexp is taken as Posix syntax 126SELECT SUBSTRING('abcdefg' FROM 'c.e') AS "cde"; 127 128-- With a parenthesized subexpression, return only what matches the subexpr 129SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde"; 130 131-- PostgreSQL extension to allow using back reference in replace string; 132SELECT regexp_replace('1112223333', E'(\\d{3})(\\d{3})(\\d{4})', E'(\\1) \\2-\\3'); 133SELECT regexp_replace('AAA BBB CCC ', E'\\s+', ' ', 'g'); 134SELECT regexp_replace('AAA', '^|$', 'Z', 'g'); 135SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi'); 136-- invalid regexp option 137SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'z'); 138 139-- set so we can tell NULL from empty string 140\pset null '\\N' 141 142-- return all matches from regexp 143SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$); 144 145-- test case insensitive 146SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i'); 147 148-- global option - more than one match 149SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g'); 150 151-- empty capture group (matched empty string) 152SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$); 153-- no match 154SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$); 155-- optional capture group did not match, null entry in array 156SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$); 157 158-- no capture groups 159SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$); 160 161-- start/end-of-line matches are of zero length 162SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '^', 'mg'); 163SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '$', 'mg'); 164SELECT regexp_matches('1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '^.?', 'mg'); 165SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '.?$', 'mg'); 166SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4', '.?$', 'mg'); 167 168-- give me errors 169SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$, 'gz'); 170SELECT regexp_matches('foobarbequebaz', $re$(barbeque$re$); 171SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque){2,1}$re$); 172 173-- split string on regexp 174SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', $re$\s+$re$) AS foo; 175SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', $re$\s+$re$); 176 177SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', $re$\s*$re$) AS foo; 178SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', $re$\s*$re$); 179SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', '') AS foo; 180SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', ''); 181-- case insensitive 182SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i') AS foo; 183SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i'); 184-- no match of pattern 185SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', 'nomatch') AS foo; 186SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', 'nomatch'); 187-- some corner cases 188SELECT regexp_split_to_array('123456','1'); 189SELECT regexp_split_to_array('123456','6'); 190SELECT regexp_split_to_array('123456','.'); 191SELECT regexp_split_to_array('123456',''); 192SELECT regexp_split_to_array('123456','(?:)'); 193SELECT regexp_split_to_array('1',''); 194-- errors 195SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'zippy') AS foo; 196SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'iz'); 197-- global option meaningless for regexp_split 198SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g') AS foo; 199SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g'); 200 201-- change NULL-display back 202\pset null '' 203 204-- E021-11 position expression 205SELECT POSITION('4' IN '1234567890') = '4' AS "4"; 206 207SELECT POSITION('5' IN '1234567890') = '5' AS "5"; 208 209-- T312 character overlay function 210SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f"; 211 212SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5) AS "yabadaba"; 213 214SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5 FOR 0) AS "yabadabadoo"; 215 216SELECT OVERLAY('babosa' PLACING 'ubb' FROM 2 FOR 4) AS "bubba"; 217 218-- 219-- test LIKE 220-- Be sure to form every test as a LIKE/NOT LIKE pair. 221-- 222 223-- simplest examples 224-- E061-04 like predicate 225SELECT 'hawkeye' LIKE 'h%' AS "true"; 226SELECT 'hawkeye' NOT LIKE 'h%' AS "false"; 227 228SELECT 'hawkeye' LIKE 'H%' AS "false"; 229SELECT 'hawkeye' NOT LIKE 'H%' AS "true"; 230 231SELECT 'hawkeye' LIKE 'indio%' AS "false"; 232SELECT 'hawkeye' NOT LIKE 'indio%' AS "true"; 233 234SELECT 'hawkeye' LIKE 'h%eye' AS "true"; 235SELECT 'hawkeye' NOT LIKE 'h%eye' AS "false"; 236 237SELECT 'indio' LIKE '_ndio' AS "true"; 238SELECT 'indio' NOT LIKE '_ndio' AS "false"; 239 240SELECT 'indio' LIKE 'in__o' AS "true"; 241SELECT 'indio' NOT LIKE 'in__o' AS "false"; 242 243SELECT 'indio' LIKE 'in_o' AS "false"; 244SELECT 'indio' NOT LIKE 'in_o' AS "true"; 245 246-- unused escape character 247SELECT 'hawkeye' LIKE 'h%' ESCAPE '#' AS "true"; 248SELECT 'hawkeye' NOT LIKE 'h%' ESCAPE '#' AS "false"; 249 250SELECT 'indio' LIKE 'ind_o' ESCAPE '$' AS "true"; 251SELECT 'indio' NOT LIKE 'ind_o' ESCAPE '$' AS "false"; 252 253-- escape character 254-- E061-05 like predicate with escape clause 255SELECT 'h%' LIKE 'h#%' ESCAPE '#' AS "true"; 256SELECT 'h%' NOT LIKE 'h#%' ESCAPE '#' AS "false"; 257 258SELECT 'h%wkeye' LIKE 'h#%' ESCAPE '#' AS "false"; 259SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true"; 260 261SELECT 'h%wkeye' LIKE 'h#%%' ESCAPE '#' AS "true"; 262SELECT 'h%wkeye' NOT LIKE 'h#%%' ESCAPE '#' AS "false"; 263 264SELECT 'h%awkeye' LIKE 'h#%a%k%e' ESCAPE '#' AS "true"; 265SELECT 'h%awkeye' NOT LIKE 'h#%a%k%e' ESCAPE '#' AS "false"; 266 267SELECT 'indio' LIKE '_ndio' ESCAPE '$' AS "true"; 268SELECT 'indio' NOT LIKE '_ndio' ESCAPE '$' AS "false"; 269 270SELECT 'i_dio' LIKE 'i$_d_o' ESCAPE '$' AS "true"; 271SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false"; 272 273SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false"; 274SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true"; 275 276SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true"; 277SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false"; 278 279-- escape character same as pattern character 280SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true"; 281SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false"; 282 283SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true"; 284SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false"; 285 286SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true"; 287SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false"; 288 289SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true"; 290SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false"; 291 292SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false"; 293SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true"; 294 295 296-- 297-- test ILIKE (case-insensitive LIKE) 298-- Be sure to form every test as an ILIKE/NOT ILIKE pair. 299-- 300 301SELECT 'hawkeye' ILIKE 'h%' AS "true"; 302SELECT 'hawkeye' NOT ILIKE 'h%' AS "false"; 303 304SELECT 'hawkeye' ILIKE 'H%' AS "true"; 305SELECT 'hawkeye' NOT ILIKE 'H%' AS "false"; 306 307SELECT 'hawkeye' ILIKE 'H%Eye' AS "true"; 308SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false"; 309 310SELECT 'Hawkeye' ILIKE 'h%' AS "true"; 311SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false"; 312 313-- 314-- test %/_ combination cases, cf bugs #4821 and #5478 315-- 316 317SELECT 'foo' LIKE '_%' as t, 'f' LIKE '_%' as t, '' LIKE '_%' as f; 318SELECT 'foo' LIKE '%_' as t, 'f' LIKE '%_' as t, '' LIKE '%_' as f; 319 320SELECT 'foo' LIKE '__%' as t, 'foo' LIKE '___%' as t, 'foo' LIKE '____%' as f; 321SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f; 322 323SELECT 'jack' LIKE '%____%' AS t; 324 325 326-- 327-- test implicit type conversion 328-- 329 330-- E021-07 character concatenation 331SELECT 'unknown' || ' and unknown' AS "Concat unknown types"; 332 333SELECT text 'text' || ' and unknown' AS "Concat text to unknown type"; 334 335SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type"; 336 337SELECT text 'text' || char(20) ' and characters' AS "Concat text to char"; 338 339SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar"; 340 341-- 342-- test substr with toasted text values 343-- 344CREATE TABLE toasttest(f1 text); 345 346insert into toasttest values(repeat('1234567890',10000)); 347insert into toasttest values(repeat('1234567890',10000)); 348 349-- 350-- Ensure that some values are uncompressed, to test the faster substring 351-- operation used in that case 352-- 353alter table toasttest alter column f1 set storage external; 354insert into toasttest values(repeat('1234567890',10000)); 355insert into toasttest values(repeat('1234567890',10000)); 356 357-- If the starting position is zero or less, then return from the start of the string 358-- adjusting the length to be consistent with the "negative start" per SQL. 359SELECT substr(f1, -1, 5) from toasttest; 360 361-- If the length is less than zero, an ERROR is thrown. 362SELECT substr(f1, 5, -1) from toasttest; 363 364-- If no third argument (length) is provided, the length to the end of the 365-- string is assumed. 366SELECT substr(f1, 99995) from toasttest; 367 368-- If start plus length is > string length, the result is truncated to 369-- string length 370SELECT substr(f1, 99995, 10) from toasttest; 371 372DROP TABLE toasttest; 373 374-- 375-- test substr with toasted bytea values 376-- 377CREATE TABLE toasttest(f1 bytea); 378 379insert into toasttest values(decode(repeat('1234567890',10000),'escape')); 380insert into toasttest values(decode(repeat('1234567890',10000),'escape')); 381 382-- 383-- Ensure that some values are uncompressed, to test the faster substring 384-- operation used in that case 385-- 386alter table toasttest alter column f1 set storage external; 387insert into toasttest values(decode(repeat('1234567890',10000),'escape')); 388insert into toasttest values(decode(repeat('1234567890',10000),'escape')); 389 390-- If the starting position is zero or less, then return from the start of the string 391-- adjusting the length to be consistent with the "negative start" per SQL. 392SELECT substr(f1, -1, 5) from toasttest; 393 394-- If the length is less than zero, an ERROR is thrown. 395SELECT substr(f1, 5, -1) from toasttest; 396 397-- If no third argument (length) is provided, the length to the end of the 398-- string is assumed. 399SELECT substr(f1, 99995) from toasttest; 400 401-- If start plus length is > string length, the result is truncated to 402-- string length 403SELECT substr(f1, 99995, 10) from toasttest; 404 405DROP TABLE toasttest; 406 407-- test internally compressing datums 408 409-- this tests compressing a datum to a very small size which exercises a 410-- corner case in packed-varlena handling: even though small, the compressed 411-- datum must be given a 4-byte header because there are no bits to indicate 412-- compression in a 1-byte header 413 414CREATE TABLE toasttest (c char(4096)); 415INSERT INTO toasttest VALUES('x'); 416SELECT length(c), c::text FROM toasttest; 417SELECT c FROM toasttest; 418DROP TABLE toasttest; 419 420-- 421-- test length 422-- 423 424SELECT length('abcdef') AS "length_6"; 425 426-- 427-- test strpos 428-- 429 430SELECT strpos('abcdef', 'cd') AS "pos_3"; 431 432SELECT strpos('abcdef', 'xy') AS "pos_0"; 433 434-- 435-- test replace 436-- 437SELECT replace('abcdef', 'de', '45') AS "abc45f"; 438 439SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo"; 440 441SELECT replace('yabadoo', 'bad', '') AS "yaoo"; 442 443-- 444-- test split_part 445-- 446select split_part('joeuser@mydatabase','@',0) AS "an error"; 447 448select split_part('joeuser@mydatabase','@',1) AS "joeuser"; 449 450select split_part('joeuser@mydatabase','@',2) AS "mydatabase"; 451 452select split_part('joeuser@mydatabase','@',3) AS "empty string"; 453 454select split_part('@joeuser@mydatabase@','@',2) AS "joeuser"; 455 456-- 457-- test to_hex 458-- 459select to_hex(256*256*256 - 1) AS "ffffff"; 460 461select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff"; 462 463-- 464-- MD5 test suite - from IETF RFC 1321 465-- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt) 466-- 467select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE"; 468 469select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE"; 470 471select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE"; 472 473select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE"; 474 475select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE"; 476 477select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE"; 478 479select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE"; 480 481select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE"; 482 483select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE"; 484 485select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE"; 486 487select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE"; 488 489select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE"; 490 491select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE"; 492 493select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE"; 494 495-- 496-- encode/decode 497-- 498SET bytea_output TO hex; 499 500SELECT encode('\x1234567890abcdef00', 'hex'); 501SELECT decode('1234567890abcdef00', 'hex'); 502SELECT encode(('\x' || repeat('1234567890abcdef0001', 7))::bytea, 'base64'); 503SELECT decode(encode(('\x' || repeat('1234567890abcdef0001', 7))::bytea, 504 'base64'), 'base64'); 505SELECT encode('\x1234567890abcdef00', 'escape'); 506SELECT decode(encode('\x1234567890abcdef00', 'escape'), 'escape'); 507 508-- 509-- get_bit/set_bit etc 510-- 511SELECT get_bit('\x1234567890abcdef00'::bytea, 43); 512SELECT get_bit('\x1234567890abcdef00'::bytea, 99); -- error 513SELECT set_bit('\x1234567890abcdef00'::bytea, 43, 0); 514SELECT set_bit('\x1234567890abcdef00'::bytea, 99, 0); -- error 515SELECT get_byte('\x1234567890abcdef00'::bytea, 3); 516SELECT get_byte('\x1234567890abcdef00'::bytea, 99); -- error 517SELECT set_byte('\x1234567890abcdef00'::bytea, 7, 11); 518SELECT set_byte('\x1234567890abcdef00'::bytea, 99, 11); -- error 519 520-- 521-- test behavior of escape_string_warning and standard_conforming_strings options 522-- 523set escape_string_warning = off; 524set standard_conforming_strings = off; 525 526show escape_string_warning; 527show standard_conforming_strings; 528 529set escape_string_warning = on; 530set standard_conforming_strings = on; 531 532show escape_string_warning; 533show standard_conforming_strings; 534 535select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6; 536 537set standard_conforming_strings = off; 538 539select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6; 540 541set escape_string_warning = off; 542set standard_conforming_strings = on; 543 544select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6; 545 546set standard_conforming_strings = off; 547 548select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6; 549 550 551-- 552-- Additional string functions 553-- 554SET bytea_output TO escape; 555 556SELECT initcap('hi THOMAS'); 557 558SELECT lpad('hi', 5, 'xy'); 559SELECT lpad('hi', 5); 560SELECT lpad('hi', -5, 'xy'); 561SELECT lpad('hello', 2); 562SELECT lpad('hi', 5, ''); 563 564SELECT rpad('hi', 5, 'xy'); 565SELECT rpad('hi', 5); 566SELECT rpad('hi', -5, 'xy'); 567SELECT rpad('hello', 2); 568SELECT rpad('hi', 5, ''); 569 570SELECT ltrim('zzzytrim', 'xyz'); 571 572SELECT translate('', '14', 'ax'); 573SELECT translate('12345', '14', 'ax'); 574 575SELECT ascii('x'); 576SELECT ascii(''); 577 578SELECT chr(65); 579SELECT chr(0); 580 581SELECT repeat('Pg', 4); 582SELECT repeat('Pg', -4); 583 584SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea); 585SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea); 586SELECT btrim(''::bytea, E'\\000'::bytea); 587SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea); 588SELECT encode(overlay(E'Th\\000omas'::bytea placing E'Th\\001omas'::bytea from 2),'escape'); 589SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 8),'escape'); 590SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 5 for 3),'escape'); 591