summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorBruce Momjian2002-08-22 03:24:01 +0000
committerBruce Momjian2002-08-22 03:24:01 +0000
commit89260124dbf300e7f28d43382bde09029a9b0cf4 (patch)
treeccd805ff14b24c9a82cde4c43d3d850f6398e58c /src/test
parentf6353c6ee4a11faa36141339a03a16bc25cd0b10 (diff)
Add:
replace(string, from, to) -- replaces all occurrences of "from" in "string" to "to" split(string, fldsep, column) -- splits "string" on "fldsep" and returns "column" number piece to_hex(int32_num) & to_hex(int64_num) -- takes integer number and returns as hex string Joe Conway
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/strings.out163
-rw-r--r--src/test/regress/sql/strings.sql93
2 files changed, 256 insertions, 0 deletions
diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out
index 67dbd1a2d92..373746ca7ac 100644
--- a/src/test/regress/expected/strings.out
+++ b/src/test/regress/expected/strings.out
@@ -573,3 +573,166 @@ SELECT text 'text' || varchar ' and varchar' AS "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));
+-- 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
+(2 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
+(2 rows)
+
+-- If start plus length is > string length, the result is truncated to
+-- string length
+SELECT substr(f1, 99995, 10) from toasttest;
+ substr
+--------
+ 567890
+ 567890
+(2 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'));
+-- 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
+(2 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
+(2 rows)
+
+-- If start plus length is > string length, the result is truncated to
+-- string length
+SELECT substr(f1, 99995, 10) from toasttest;
+ substr
+--------
+ 567890
+ 567890
+(2 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
+--
+select split('joeuser@mydatabase','@',0) AS "an error";
+ERROR: field position must be > 0
+select split('joeuser@mydatabase','@',1) AS "joeuser";
+ joeuser
+---------
+ joeuser
+(1 row)
+
+select split('joeuser@mydatabase','@',2) AS "mydatabase";
+ mydatabase
+------------
+ mydatabase
+(1 row)
+
+select split('joeuser@mydatabase','@',3) AS "empty string";
+ empty string
+--------------
+
+(1 row)
+
+select split('@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)
+
diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql
index 3127d0ebffc..af83a0b5715 100644
--- a/src/test/regress/sql/strings.sql
+++ b/src/test/regress/sql/strings.sql
@@ -197,3 +197,96 @@ 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));
+
+-- 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 length
+SELECT 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'));
+
+-- 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 length
+SELECT substr(f1, 99995, 10) 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
+--
+select split('joeuser@mydatabase','@',0) AS "an error";
+
+select split('joeuser@mydatabase','@',1) AS "joeuser";
+
+select split('joeuser@mydatabase','@',2) AS "mydatabase";
+
+select split('joeuser@mydatabase','@',3) AS "empty string";
+
+select split('@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";