diff --git a/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs b/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs index 9a82c8eed..6ae55abb1 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs @@ -979,7 +979,9 @@ protected virtual Expression VisitRegexMatch(PgRegexMatchExpression expression, // PG regexps are single-line by default if (options == RegexOptions.Singleline) { + Sql.Append("("); Visit(expression.Pattern); + Sql.Append(")"); return expression; } @@ -1011,9 +1013,9 @@ protected virtual Expression VisitRegexMatch(PgRegexMatchExpression expression, if (constantPattern is null) { - Sql.Append("' || "); + Sql.Append("' || ("); Visit(expression.Pattern); - Sql.Append(")"); + Sql.Append("))"); } else { diff --git a/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs index fe360fda2..2def1992f 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs @@ -101,7 +101,7 @@ await AssertQuery( SELECT c."CustomerID", c."Address", c."City", c."CompanyName", c."ContactName", c."ContactTitle", c."Country", c."Fax", c."Phone", c."PostalCode", c."Region" FROM "Customers" AS c -WHERE c."CompanyName" ~ ('(?p)' || @pattern) +WHERE c."CompanyName" ~ ('(?p)' || (@pattern)) """); } @@ -197,7 +197,7 @@ await AssertQuery( """ SELECT c."CustomerID", c."Address", c."City", c."CompanyName", c."ContactName", c."ContactTitle", c."Country", c."Fax", c."Phone", c."PostalCode", c."Region" FROM "Customers" AS c -WHERE c."CompanyName" ~ '^A' +WHERE c."CompanyName" ~ ('^A') """); } @@ -213,7 +213,7 @@ await AssertQuery( """ SELECT c."CustomerID", c."Address", c."City", c."CompanyName", c."ContactName", c."ContactTitle", c."Country", c."Fax", c."Phone", c."PostalCode", c."Region" FROM "Customers" AS c -WHERE c."CompanyName" ~* '^a' +WHERE c."CompanyName" ~* ('^a') """); } diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/StringTranslationsNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/StringTranslationsNpgsqlTest.cs index b72d06901..46ed613eb 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/StringTranslationsNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/StringTranslationsNpgsqlTest.cs @@ -1579,7 +1579,7 @@ public override async Task Regex_IsMatch_constant_input() """ SELECT b."Id", b."Bool", b."Byte", b."ByteArray", b."DateOnly", b."DateTime", b."DateTimeOffset", b."Decimal", b."Double", b."Enum", b."FlagsEnum", b."Float", b."Guid", b."Int", b."Long", b."Short", b."String", b."TimeOnly", b."TimeSpan" FROM "BasicTypesEntities" AS b -WHERE 'Seattle' ~ ('(?p)' || b."String") +WHERE 'Seattle' ~ ('(?p)' || (b."String")) """); }