diff --git a/edb/lib/std/30-regexpfuncs.edgeql b/edb/lib/std/30-regexpfuncs.edgeql index dc7d0c65be1..8bc0626a152 100644 --- a/edb/lib/std/30-regexpfuncs.edgeql +++ b/edb/lib/std/30-regexpfuncs.edgeql @@ -27,7 +27,7 @@ std::re_match(pattern: std::str, str: std::str) -> array 'Find the first regular expression match in a string.'; SET volatility := 'Immutable'; USING SQL $$ - SELECT regexp_matches("str", "pattern"); + SELECT array_replace(regexp_matches("str", "pattern"), NULL, ''); $$; }; @@ -39,7 +39,7 @@ std::re_match_all(pattern: std::str, str: std::str) -> SET OF array 'Find all regular expression matches in a string.'; SET volatility := 'Immutable'; USING SQL $$ - SELECT regexp_matches("str", "pattern", 'g'); + SELECT array_replace(regexp_matches("str", "pattern", 'g'), NULL, ''); $$; }; diff --git a/edb/pgsql/patches.py b/edb/pgsql/patches.py index b26ee6a43ec..56467037b65 100644 --- a/edb/pgsql/patches.py +++ b/edb/pgsql/patches.py @@ -170,4 +170,22 @@ def _setup_patches(patches: list[tuple[str, str]]) -> list[tuple[str, str]]: }; } '''), + # === 5.8 + ('edgeql', ''' +ALTER FUNCTION +std::re_match(pattern: std::str, str: std::str) +{ + USING SQL $$ + SELECT array_replace(regexp_matches("str", "pattern"), NULL, ''); + $$; +}; +ALTER FUNCTION +std::re_match_all(pattern: std::str, str: std::str) +{ + USING SQL $$ + SELECT array_replace(regexp_matches("str", "pattern", 'g'), NULL, ''); + $$; +}; +'''), + ]) diff --git a/tests/test_edgeql_functions.py b/tests/test_edgeql_functions.py index dff66d1f5a8..350f07cb07d 100644 --- a/tests/test_edgeql_functions.py +++ b/tests/test_edgeql_functions.py @@ -1054,6 +1054,16 @@ async def test_edgeql_functions_re_match_01(self): [['Ab'], ['a']], ) + await self.assert_query_result( + r''' + select re_match( + r"(foo)?bar", + 'barbar', + ) + ''', + [[""]], + ) + async def test_edgeql_functions_re_match_02(self): await self.assert_query_result( r''' @@ -1135,6 +1145,16 @@ async def test_edgeql_functions_re_match_all_01(self): [['Ab'], ['a'], ['a'], ['aB'], ['ab']], ) + await self.assert_query_result( + r''' + select re_match_all( + r"(foo)?bar", + 'barbar', + ) + ''', + [[""], [""]], + ) + async def test_edgeql_functions_re_test_01(self): await self.assert_query_result( r'''SELECT re_test('ac', 'AbabaB');''',