strings.sql
来自「postgresql8.3.4源码,开源数据库」· SQL 代码 · 共 453 行 · 第 1/2 页
SQL
453 行
SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true";SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false";SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true";SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false";SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false";SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true";---- test ILIKE (case-insensitive LIKE)-- Be sure to form every test as an ILIKE/NOT ILIKE pair.--SELECT 'hawkeye' ILIKE 'h%' AS "true";SELECT 'hawkeye' NOT ILIKE 'h%' AS "false";SELECT 'hawkeye' ILIKE 'H%' AS "true";SELECT 'hawkeye' NOT ILIKE 'H%' AS "false";SELECT 'hawkeye' ILIKE 'H%Eye' AS "true";SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false";SELECT 'Hawkeye' ILIKE 'h%' AS "true";SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false";---- test implicit type conversion---- E021-07 character concatenationSELECT 'unknown' || ' and unknown' AS "Concat unknown types";SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";---- 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;-- If the length is less than zero, an ERROR is thrown.SELECT substr(f1, 5, -1) from toasttest;-- If no third argument (length) is provided, the length to the end of the-- string is assumed.SELECT substr(f1, 99995) from toasttest;-- If start plus length is > string length, the result is truncated to-- string lengthSELECT substr(f1, 99995, 10) from toasttest;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;-- If the length is less than zero, an ERROR is thrown.SELECT substr(f1, 5, -1) from toasttest;-- If no third argument (length) is provided, the length to the end of the-- string is assumed.SELECT substr(f1, 99995) from toasttest;-- If start plus length is > string length, the result is truncated to-- string lengthSELECT substr(f1, 99995, 10) from toasttest;DROP TABLE toasttest;-- test internally compressing datums-- this tests compressing a datum to a very small size which exercises a-- corner case in packed-varlena handling: even though small, the compressed-- datum must be given a 4-byte header because there are no bits to indicate-- compression in a 1-byte headerCREATE TABLE toasttest (c char(4096));INSERT INTO toasttest VALUES('x');SELECT length(c), c::text FROM toasttest;SELECT c FROM toasttest;DROP TABLE toasttest;---- test length--SELECT length('abcdef') AS "length_6";---- test strpos--SELECT strpos('abcdef', 'cd') AS "pos_3";SELECT strpos('abcdef', 'xy') AS "pos_0";---- test replace--SELECT replace('abcdef', 'de', '45') AS "abc45f";SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";SELECT replace('yabadoo', 'bad', '') AS "yaoo";---- test split_part--select split_part('joeuser@mydatabase','@',0) AS "an error";select split_part('joeuser@mydatabase','@',1) AS "joeuser";select split_part('joeuser@mydatabase','@',2) AS "mydatabase";select split_part('joeuser@mydatabase','@',3) AS "empty string";select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";---- test to_hex--select to_hex(256*256*256 - 1) AS "ffffff";select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";---- MD5 test suite - from IETF RFC 1321-- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)--select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";---- test behavior of escape_string_warning and standard_conforming_strings options--set escape_string_warning = off;set standard_conforming_strings = off;show escape_string_warning;show standard_conforming_strings;set escape_string_warning = on;set standard_conforming_strings = on;show escape_string_warning;show standard_conforming_strings;select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;set standard_conforming_strings = off;select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;set escape_string_warning = off;set standard_conforming_strings = on;select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;set standard_conforming_strings = off;select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?