mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-09 06:42:57 +00:00
* feat: adds format, regex_extract function and more type tests Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix: forgot functions Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * chore: forgot null type Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test: forgot date type Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat: remove format function Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test: update results after upgrading datafusion Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
58 lines
1.5 KiB
SQL
58 lines
1.5 KiB
SQL
-- String REPLACE function tests
|
|
|
|
-- Basic REPLACE function
|
|
SELECT REPLACE('hello world', 'world', 'universe');
|
|
|
|
SELECT REPLACE('hello world', 'xyz', 'abc');
|
|
|
|
SELECT REPLACE('hello hello hello', 'hello', 'hi');
|
|
|
|
-- REPLACE with empty strings
|
|
SELECT REPLACE('hello world', 'world', '');
|
|
|
|
SELECT REPLACE('hello world', '', 'xyz');
|
|
|
|
SELECT REPLACE('', 'xyz', 'abc');
|
|
|
|
-- Case sensitive replacement
|
|
SELECT REPLACE('Hello World', 'hello', 'hi');
|
|
|
|
SELECT REPLACE('Hello World', 'Hello', 'Hi');
|
|
|
|
-- NULL handling
|
|
SELECT REPLACE(NULL, 'world', 'universe');
|
|
|
|
SELECT REPLACE('hello world', NULL, 'universe');
|
|
|
|
SELECT REPLACE('hello world', 'world', NULL);
|
|
|
|
-- Test with table data
|
|
CREATE TABLE replace_test(s VARCHAR, old_str VARCHAR, new_str VARCHAR, ts TIMESTAMP TIME INDEX);
|
|
|
|
INSERT INTO replace_test VALUES
|
|
('hello world', 'world', 'universe', 1000),
|
|
('programming language', 'language', 'paradigm', 2000),
|
|
('test test test', 'test', 'exam', 3000),
|
|
('no match here', 'xyz', 'abc', 4000);
|
|
|
|
SELECT s, old_str, new_str, REPLACE(s, old_str, new_str) FROM replace_test ORDER BY ts;
|
|
|
|
-- Unicode replacement
|
|
SELECT REPLACE('hello 世界', '世界', 'world');
|
|
|
|
SELECT REPLACE('café shop', 'é', 'e');
|
|
|
|
SELECT REPLACE('🚀 rocket 🚀', '🚀', '✈️');
|
|
|
|
-- Multiple character replacement
|
|
SELECT REPLACE('hello-world-test', '-', '_');
|
|
|
|
SELECT REPLACE('abc::def::ghi', '::', '-->');
|
|
|
|
-- Overlapping patterns
|
|
SELECT REPLACE('ababab', 'ab', 'xy');
|
|
|
|
SELECT REPLACE('aaa', 'aa', 'b');
|
|
|
|
DROP TABLE replace_test;
|