📄 strings.out
字号:
SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false"; false ------- f(1 row)SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true"; true ------ t(1 row)SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true"; true ------ t(1 row)SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false"; false ------- f(1 row)-- escape character same as pattern characterSELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true"; true ------ t(1 row)SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false"; false ------- f(1 row)SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true"; true ------ t(1 row)SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false"; false ------- f(1 row)SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true"; true ------ t(1 row)SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false"; false ------- f(1 row)SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true"; true ------ t(1 row)SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false"; false ------- f(1 row)SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false"; false ------- f(1 row)SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true"; true ------ t(1 row)---- test ILIKE (case-insensitive LIKE)-- Be sure to form every test as an ILIKE/NOT ILIKE pair.--SELECT 'hawkeye' ILIKE 'h%' AS "true"; true ------ t(1 row)SELECT 'hawkeye' NOT ILIKE 'h%' AS "false"; false ------- f(1 row)SELECT 'hawkeye' ILIKE 'H%' AS "true"; true ------ t(1 row)SELECT 'hawkeye' NOT ILIKE 'H%' AS "false"; false ------- f(1 row)SELECT 'hawkeye' ILIKE 'H%Eye' AS "true"; true ------ t(1 row)SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false"; false ------- f(1 row)SELECT 'Hawkeye' ILIKE 'h%' AS "true"; true ------ t(1 row)SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false"; false ------- f(1 row)---- test implicit type conversion---- E021-07 character concatenationSELECT 'unknown' || ' and unknown' AS "Concat unknown types"; Concat unknown types ---------------------- unknown and unknown(1 row)SELECT text 'text' || ' and unknown' AS "Concat text to unknown type"; Concat text to unknown type ----------------------------- text and unknown(1 row)SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type"; Concat char to unknown type ----------------------------- characters and text(1 row)SELECT text 'text' || char(20) ' and characters' AS "Concat text to char"; Concat text to char --------------------- text and characters(1 row)SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar"; Concat text to varchar ------------------------ text and varchar(1 row)---- test substr with toasted text values--CREATE TABLE toasttest(f1 text);insert into toasttest values(repeat('1234567890',10000));insert into toasttest values(repeat('1234567890',10000));---- Ensure that some values are uncompressed, to test the faster substring-- operation used in that case--alter table toasttest alter column f1 set storage external;insert into toasttest values(repeat('1234567890',10000));insert into toasttest values(repeat('1234567890',10000));-- If the starting position is zero or less, then return from the start of the string-- adjusting the length to be consistent with the "negative start" per SQL92.SELECT substr(f1, -1, 5) from toasttest; substr -------- 123 123 123 123(4 rows)-- If the length is less than zero, an ERROR is thrown.SELECT substr(f1, 5, -1) from toasttest;ERROR: negative substring length not allowed-- If no third argument (length) is provided, the length to the end of the-- string is assumed.SELECT substr(f1, 99995) from toasttest; substr -------- 567890 567890 567890 567890(4 rows)-- If start plus length is > string length, the result is truncated to-- string lengthSELECT substr(f1, 99995, 10) from toasttest; substr -------- 567890 567890 567890 567890(4 rows)DROP TABLE toasttest;---- test substr with toasted bytea values--CREATE TABLE toasttest(f1 bytea);insert into toasttest values(decode(repeat('1234567890',10000),'escape'));insert into toasttest values(decode(repeat('1234567890',10000),'escape'));---- Ensure that some values are uncompressed, to test the faster substring-- operation used in that case--alter table toasttest alter column f1 set storage external;insert into toasttest values(decode(repeat('1234567890',10000),'escape'));insert into toasttest values(decode(repeat('1234567890',10000),'escape'));-- If the starting position is zero or less, then return from the start of the string-- adjusting the length to be consistent with the "negative start" per SQL92.SELECT substr(f1, -1, 5) from toasttest; substr -------- 123 123 123 123(4 rows)-- If the length is less than zero, an ERROR is thrown.SELECT substr(f1, 5, -1) from toasttest;ERROR: negative substring length not allowed-- If no third argument (length) is provided, the length to the end of the-- string is assumed.SELECT substr(f1, 99995) from toasttest; substr -------- 567890 567890 567890 567890(4 rows)-- If start plus length is > string length, the result is truncated to-- string lengthSELECT substr(f1, 99995, 10) from toasttest; substr -------- 567890 567890 567890 567890(4 rows)DROP TABLE toasttest;---- test length--SELECT length('abcdef') AS "length_6"; length_6 ---------- 6(1 row)---- test strpos--SELECT strpos('abcdef', 'cd') AS "pos_3"; pos_3 ------- 3(1 row)SELECT strpos('abcdef', 'xy') AS "pos_0"; pos_0 ------- 0(1 row)---- test replace--SELECT replace('abcdef', 'de', '45') AS "abc45f"; abc45f -------- abc45f(1 row)SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo"; ya123da123doo --------------- ya123da123doo(1 row)SELECT replace('yabadoo', 'bad', '') AS "yaoo"; yaoo ------ yaoo(1 row)---- test split_part--select split_part('joeuser@mydatabase','@',0) AS "an error";ERROR: field position must be greater than zeroselect split_part('joeuser@mydatabase','@',1) AS "joeuser"; joeuser --------- joeuser(1 row)select split_part('joeuser@mydatabase','@',2) AS "mydatabase"; mydatabase ------------ mydatabase(1 row)select split_part('joeuser@mydatabase','@',3) AS "empty string"; empty string -------------- (1 row)select split_part('@joeuser@mydatabase@','@',2) AS "joeuser"; joeuser --------- joeuser(1 row)---- test to_hex--select to_hex(256*256*256 - 1) AS "ffffff"; ffffff -------- ffffff(1 row)select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff"; ffffffff ---------- ffffffff(1 row)---- MD5 test suite - from IETF RFC 1321-- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)--select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE"; TRUE ------ t(1 row)select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE"; TRUE ------ t(1 row)select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE"; TRUE ------ t(1 row)select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE"; TRUE ------ t(1 row)select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE"; TRUE ------ t(1 row)select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE"; TRUE ------ t(1 row)select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE"; TRUE ------ t(1 row)select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE"; TRUE ------ t(1 row)select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE"; TRUE ------ t(1 row)select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE"; TRUE ------ t(1 row)select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE"; TRUE ------ t(1 row)select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE"; TRUE ------ t(1 row)select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE"; TRUE ------ t(1 row)select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE"; TRUE ------ t(1 row)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -