Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate parentheses for PostgresBinaryExpression #1653

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,6 @@ public virtual Expression VisitPgFunction([NotNull] PostgresFunctionExpression e
}

static bool RequiresBrackets(SqlExpression expression)
=> expression is SqlBinaryExpression || expression is LikeExpression;
=> expression is SqlBinaryExpression || expression is LikeExpression || expression is PostgresBinaryExpression;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public FullTextSearchDbFunctionsNpgsqlTest(NorthwindQueryNpgsqlFixture<NoopModel
{
Fixture = fixture;
Fixture.TestSqlLoggerFactory.Clear();
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
// Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

[Fact]
Expand Down Expand Up @@ -864,7 +864,7 @@ public void Complex_query()
public void Unaccent()
{
using var context = CreateContext();
var _ = context.Customers
_ = context.Customers
.Select(x => EF.Functions.Unaccent(x.ContactName))
.FirstOrDefault();

Expand All @@ -877,7 +877,7 @@ public void Unaccent()
public void Unaccent_with_constant_regdictionary()
{
using var context = CreateContext();
var _ = context.Customers
_ = context.Customers
.Select(x => EF.Functions.Unaccent("unaccent", x.ContactName))
.FirstOrDefault();

Expand All @@ -891,7 +891,7 @@ public void Unaccent_with_parameter_regdictionary()
{
using var context = CreateContext();
var regDictionary = "unaccent";
var _ = context.Customers
_ = context.Customers
.Select(x => EF.Functions.Unaccent(regDictionary, x.ContactName))
.FirstOrDefault();

Expand All @@ -903,6 +903,20 @@ SELECT unaccent(@__regDictionary_1::regdictionary, c.""ContactName"")
LIMIT 1");
}

[Fact] // #1652
public void Match_and_boolean_operator_precedence()
{
using var context = CreateContext();
_ = context.Customers
.Count(c => EF.Functions.ToTsVector(c.ContactTitle)
.Matches(EF.Functions.ToTsQuery("owner").Or(EF.Functions.ToTsQuery("foo"))));

AssertSql(
@"SELECT COUNT(*)::INT
FROM ""Customers"" AS c
WHERE to_tsvector(c.""ContactTitle"") @@ (to_tsquery('owner') || to_tsquery('foo'))");
}

void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down