should be it
This commit is contained in:
112
external/duckdb/test/sql/function/string/regex_extract.test
vendored
Normal file
112
external/duckdb/test/sql/function/string/regex_extract.test
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
# name: test/sql/function/string/regex_extract.test
|
||||
# description: regex extract test
|
||||
# group: [string]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', 'b..')
|
||||
----
|
||||
bar
|
||||
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', 'B..')
|
||||
----
|
||||
(empty)
|
||||
|
||||
# pass in regex options
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', 'B..', 0, 'i')
|
||||
----
|
||||
bar
|
||||
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', 'b..', 1)
|
||||
----
|
||||
(empty)
|
||||
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', '(b..)(b..)')
|
||||
----
|
||||
barbaz
|
||||
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', '(b..)(b..)', 1)
|
||||
----
|
||||
bar
|
||||
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', '(b..)(b..)', 2)
|
||||
----
|
||||
baz
|
||||
|
||||
statement error
|
||||
SELECT regexp_extract('foobarbaz', '(b..)(b..)', -1)
|
||||
----
|
||||
<REGEX>:.*Invalid Input Error: Group index must be.*
|
||||
|
||||
statement error
|
||||
SELECT regexp_extract('foobarbaz', '(b..)(b..)', 42)
|
||||
----
|
||||
<REGEX>:.*Invalid Input Error: Group index must be.*
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test (s VARCHAR, p VARCHAR, i INT)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES
|
||||
('foobarbaz', 'b..', 0),
|
||||
('foobarbaz', 'b..', 1),
|
||||
('foobarbaz', '(b..)(b..)', 0),
|
||||
('foobarbaz', '(b..)(b..)', 1),
|
||||
('foobarbaz', '(b..)(b..)', 2)
|
||||
|
||||
statement error
|
||||
SELECT regexp_extract(s, p, i) FROM test
|
||||
----
|
||||
<REGEX>:.*Invalid Input Error.*must be a constant.*
|
||||
|
||||
query T
|
||||
SELECT regexp_extract(s, p, 0) FROM test
|
||||
----
|
||||
bar
|
||||
bar
|
||||
barbaz
|
||||
barbaz
|
||||
barbaz
|
||||
|
||||
query T
|
||||
SELECT regexp_extract(s, 'b..', 0) FROM test
|
||||
----
|
||||
bar
|
||||
bar
|
||||
bar
|
||||
bar
|
||||
bar
|
||||
|
||||
statement error
|
||||
SELECT regexp_extract(s, '(b..)(b..)', i) FROM test
|
||||
----
|
||||
<REGEX>:.*Invalid Input Error.*must be a constant.*
|
||||
|
||||
# null values
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', NULL, 0)
|
||||
----
|
||||
NULL
|
||||
|
||||
query T
|
||||
SELECT regexp_extract('foobarbaz', 'b..', NULL)
|
||||
----
|
||||
(empty)
|
||||
|
||||
query T
|
||||
SELECT regexp_extract(NULL, 'b..')
|
||||
----
|
||||
NULL
|
||||
|
||||
statement error
|
||||
SELECT regexp_extract('foobarbaz', 'b..', '1')
|
||||
----
|
||||
<REGEX>:.*Binder Error.*Could not choose a best candidate.*
|
||||
Reference in New Issue
Block a user