-- String LIKE pattern matching tests -- Basic LIKE patterns SELECT 'hello world' LIKE 'hello%'; +-----------------------------------------+ | Utf8("hello world") LIKE Utf8("hello%") | +-----------------------------------------+ | true | +-----------------------------------------+ SELECT 'hello world' LIKE '%world'; +-----------------------------------------+ | Utf8("hello world") LIKE Utf8("%world") | +-----------------------------------------+ | true | +-----------------------------------------+ SELECT 'hello world' LIKE '%llo%'; +----------------------------------------+ | Utf8("hello world") LIKE Utf8("%llo%") | +----------------------------------------+ | true | +----------------------------------------+ SELECT 'hello world' LIKE 'hello_world'; +----------------------------------------------+ | Utf8("hello world") LIKE Utf8("hello_world") | +----------------------------------------------+ | true | +----------------------------------------------+ SELECT 'hello world' LIKE 'hello world'; +----------------------------------------------+ | Utf8("hello world") LIKE Utf8("hello world") | +----------------------------------------------+ | true | +----------------------------------------------+ -- LIKE with NOT SELECT 'hello world' NOT LIKE 'goodbye%'; +-----------------------------------------------+ | Utf8("hello world") NOT LIKE Utf8("goodbye%") | +-----------------------------------------------+ | true | +-----------------------------------------------+ SELECT 'hello world' NOT LIKE 'hello%'; +---------------------------------------------+ | Utf8("hello world") NOT LIKE Utf8("hello%") | +---------------------------------------------+ | false | +---------------------------------------------+ -- Case sensitivity SELECT 'Hello World' LIKE 'hello%'; +-----------------------------------------+ | Utf8("Hello World") LIKE Utf8("hello%") | +-----------------------------------------+ | false | +-----------------------------------------+ SELECT 'Hello World' ILIKE 'hello%'; +------------------------------------------+ | Utf8("Hello World") ILIKE Utf8("hello%") | +------------------------------------------+ | true | +------------------------------------------+ SELECT 'Hello World' ILIKE 'HELLO%'; +------------------------------------------+ | Utf8("Hello World") ILIKE Utf8("HELLO%") | +------------------------------------------+ | true | +------------------------------------------+ -- Test with table data CREATE TABLE like_test("name" VARCHAR, email VARCHAR, ts TIMESTAMP TIME INDEX); Affected Rows: 0 INSERT INTO like_test VALUES ('John Doe', 'john@example.com', 1000), ('Jane Smith', 'jane@gmail.com', 2000), ('Bob Wilson', 'bob@yahoo.com', 3000), ('Alice Johnson', 'alice@company.org', 4000), ('Charlie Brown', 'charlie@test.net', 5000); Affected Rows: 5 -- Pattern matching on names SELECT "name" FROM like_test WHERE "name" LIKE 'J%' ORDER BY ts; +------------+ | name | +------------+ | John Doe | | Jane Smith | +------------+ SELECT "name" FROM like_test WHERE "name" LIKE '%son' ORDER BY ts; +---------------+ | name | +---------------+ | Bob Wilson | | Alice Johnson | +---------------+ -- Contains space SELECT "name" FROM like_test WHERE "name" LIKE '% %' ORDER BY ts; +---------------+ | name | +---------------+ | John Doe | | Jane Smith | | Bob Wilson | | Alice Johnson | | Charlie Brown | +---------------+ -- Pattern matching on emails SELECT "name", email FROM like_test WHERE email LIKE '%@gmail.com' ORDER BY ts; +------------+----------------+ | name | email | +------------+----------------+ | Jane Smith | jane@gmail.com | +------------+----------------+ SELECT "name", email FROM like_test WHERE email LIKE '%.com' ORDER BY ts; +------------+------------------+ | name | email | +------------+------------------+ | John Doe | john@example.com | | Jane Smith | jane@gmail.com | | Bob Wilson | bob@yahoo.com | +------------+------------------+ SELECT "name", email FROM like_test WHERE email LIKE '%@%.org' ORDER BY ts; +---------------+-------------------+ | name | email | +---------------+-------------------+ | Alice Johnson | alice@company.org | +---------------+-------------------+ -- Underscore wildcard SELECT "name" FROM like_test WHERE "name" LIKE 'Jo__ ___' ORDER BY ts; +----------+ | name | +----------+ | John Doe | +----------+ SELECT email FROM like_test WHERE email LIKE '____@%' ORDER BY ts; +------------------+ | email | +------------------+ | john@example.com | | jane@gmail.com | +------------------+ -- Multiple wildcards -- Contains 'o' SELECT "name" FROM like_test WHERE "name" LIKE '%o%' ORDER BY ts; +---------------+ | name | +---------------+ | John Doe | | Bob Wilson | | Alice Johnson | | Charlie Brown | +---------------+ -- 'a' before and after @ SELECT email FROM like_test WHERE email LIKE '%a%@%a%' ORDER BY ts; +-------------------+ | email | +-------------------+ | jane@gmail.com | | alice@company.org | +-------------------+ -- Escaping special characters CREATE TABLE escape_test("text" VARCHAR, ts TIMESTAMP TIME INDEX); Affected Rows: 0 INSERT INTO escape_test VALUES ('100% complete', 1000), ('test_file.txt', 2000), ('50% done', 3000), ('backup_2023.sql', 4000); Affected Rows: 4 -- Need to escape % and _ -- Contains % SELECT "text" FROM escape_test WHERE "text" LIKE '%\%%' ORDER BY ts; +---------------+ | text | +---------------+ | 100% complete | | 50% done | +---------------+ -- Contains _ SELECT "text" FROM escape_test WHERE "text" LIKE '%\_%' ORDER BY ts; +-----------------+ | text | +-----------------+ | test_file.txt | | backup_2023.sql | +-----------------+ -- Unicode pattern matching CREATE TABLE unicode_like(s VARCHAR, ts TIMESTAMP TIME INDEX); Affected Rows: 0 INSERT INTO unicode_like VALUES ('Hello 世界', 1000), ('🚀 rocket', 2000), ('café shop', 3000); Affected Rows: 3 SELECT s FROM unicode_like WHERE s LIKE '%世界' ORDER BY ts; +------------+ | s | +------------+ | Hello 世界 | +------------+ SELECT s FROM unicode_like WHERE s LIKE '🚀%' ORDER BY ts; +-----------+ | s | +-----------+ | 🚀 rocket | +-----------+ SELECT s FROM unicode_like WHERE s LIKE '%é%' ORDER BY ts; +-----------+ | s | +-----------+ | café shop | +-----------+ DROP TABLE like_test; Affected Rows: 0 DROP TABLE escape_test; Affected Rows: 0 DROP TABLE unicode_like; Affected Rows: 0