Skip to content
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
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<EFCoreVersion>11.0.0-preview.5.26227.124</EFCoreVersion>
<MicrosoftExtensionsVersion>11.0.0-preview.5.26227.124</MicrosoftExtensionsVersion>
<MicrosoftExtensionsConfigurationVersion>11.0.0-preview.5.26227.124</MicrosoftExtensionsConfigurationVersion>
<EFCoreVersion>11.0.0-preview.5.26251.112</EFCoreVersion>
<MicrosoftExtensionsVersion>11.0.0-preview.5.26251.112</MicrosoftExtensionsVersion>
<MicrosoftExtensionsConfigurationVersion>11.0.0-preview.5.26251.112</MicrosoftExtensionsConfigurationVersion>
<NpgsqlVersion>10.0.0</NpgsqlVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ SqlExpression Upper()
=> _sqlExpressionFactory.Convert(
_sqlExpressionFactory.Subtract(
Upper(),
_sqlExpressionFactory.Constant(Period.FromDays(1), _periodTypeMapping)), typeof(LocalDate),
_sqlExpressionFactory.Constant(Period.FromDays(1), _periodTypeMapping),
_typeMappingSource.FindMapping(typeof(LocalDateTime))), typeof(LocalDate),
_typeMappingSource.FindMapping(typeof(LocalDate))),

nameof(DateInterval.Length) => _sqlExpressionFactory.Subtract(Upper(), Lower()),
Expand Down
8 changes: 8 additions & 0 deletions src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,14 @@ protected virtual Expression VisitArrayAny(PgAnyExpression expression)

Visit(expression.Array);

// When the array operand is a scalar subquery, PostgreSQL interprets = ANY(subquery) as a subquery comparison
// (comparing against each row), not as an array comparison. We need to add an explicit cast to force
// PostgreSQL to treat it as an array expression (see #1803).
if (expression.Array is ScalarSubqueryExpression { TypeMapping.StoreType: var storeType })
{
Sql.Append("::").Append(storeType);
}

Sql.Append(")");

return expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,14 @@ SqlConstantExpression or PgNewArrayExpression

// Similar to ParameterExpression below, but when a bare subquery is present inside ANY(), PostgreSQL just compares
// against each of its resulting rows (just like IN). To "extract" the array result of the scalar subquery, we need
// to add an explicit cast (see #1803).
// to add an explicit cast (see #1803). This is handled in the SQL generator (VisitArrayAny) rather than via
// SqlUnaryExpression(Convert), since it's a same-type cast that would be removed by EF's simplifier.
ScalarSubqueryExpression subqueryExpression
=> BuildSimplifiedShapedQuery(
source,
_sqlExpressionFactory.Any(
translatedItem,
_sqlExpressionFactory.Convert(
subqueryExpression, subqueryExpression.Type, subqueryExpression.TypeMapping),
subqueryExpression,
PgAnyOperatorType.Equal)),

// For ParameterExpression, and for all other cases - e.g. array returned from some function -
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private SqlBinaryExpression ApplyTypeMappingOnSqlBinary(SqlBinaryExpression bina
{
var newLeft = ApplyTypeMapping(left, typeMapping);
var newRight = ApplyDefaultTypeMapping(right);
return new SqlBinaryExpression(binary.OperatorType, newLeft, newRight, binary.Type, newLeft.TypeMapping);
return new SqlBinaryExpression(binary.OperatorType, newLeft, newRight, binary.Type, typeMapping ?? newLeft.TypeMapping);
}

// DateTime - DateTime => TimeSpan
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.PG/Update/Internal/NpgsqlUpdateSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected override void AppendUpdateColumnValue(

if (segment.IsArray)
{
stringBuilder.Append(jsonPath.Ordinals[ordinalIndex++]);
stringBuilder.Append(jsonPath.Indices[ordinalIndex++]);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ await AssertQuery(

SELECT m."Id", m."CodeName", m."Date", m."Difficulty", m."Duration", m."Rating", m."Time", m."Timeline"
FROM "Missions" AS m
WHERE date_trunc('day', m."Timeline" AT TIME ZONE 'UTC')::timestamp >= @dateTimeOffset_Date
WHERE date_trunc('day', m."Timeline" AT TIME ZONE 'UTC') >= @dateTimeOffset_Date
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ await AssertQuery(

SELECT m."Id", m."CodeName", m."Date", m."Difficulty", m."Duration", m."Rating", m."Time", m."Timeline"
FROM "Missions" AS m
WHERE date_trunc('day', m."Timeline" AT TIME ZONE 'UTC')::timestamp >= @dateTimeOffset_Date
WHERE date_trunc('day', m."Timeline" AT TIME ZONE 'UTC') >= @dateTimeOffset_Date
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ await AssertQuery(

SELECT m."Id", m."CodeName", m."Date", m."Difficulty", m."Duration", m."Rating", m."Time", m."Timeline"
FROM "Missions" AS m
WHERE date_trunc('day', m."Timeline" AT TIME ZONE 'UTC')::timestamp >= @dateTimeOffset_Date
WHERE date_trunc('day', m."Timeline" AT TIME ZONE 'UTC') >= @dateTimeOffset_Date
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public override async Task SqlQuery_composed_Join(bool async)

AssertSql(
"""
SELECT o."OrderID", o."CustomerID", o."EmployeeID", o."OrderDate", s."Value"::int AS p
SELECT o."OrderID", o."CustomerID", o."EmployeeID", o."OrderDate", s."Value" AS p
FROM "Orders" AS o
INNER JOIN (
SELECT "ProductID" AS "Value" FROM "Products"
) AS s ON o."OrderID" = s."Value"::int
) AS s ON o."OrderID" = s."Value"
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public override async Task Inline_collection_with_single_parameter_element_Count
FROM "PrimitiveCollectionsEntity" AS p
WHERE (
SELECT count(*)::int
FROM (VALUES (@i::int)) AS v("Value")
FROM (VALUES (@i)) AS v("Value")
WHERE v."Value" > p."Id") = 1
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override async Task First()
"""
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 length(b."ByteArray") >= 1 AND get_byte(b."ByteArray", 0)::smallint = 222
WHERE length(b."ByteArray") >= 1 AND get_byte(b."ByteArray", 0) = 222
""");
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public override async Task SequenceEqual()
}

[ConditionalFact]
public virtual async Task Any()
public override async Task Any()
{
await AssertQuery(ss => ss.Set<BasicTypesEntity>().Where(e => e.ByteArray.Any()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void StartsWith_param_instance()

SELECT s."Id", s."CaseInsensitiveText"
FROM "SomeEntities" AS s
WHERE left(@param, length(s."CaseInsensitiveText"))::citext = s."CaseInsensitiveText"
WHERE left(@param, length(s."CaseInsensitiveText")) = s."CaseInsensitiveText"
LIMIT 2
""");
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public void EndsWith_param_instance()

SELECT s."Id", s."CaseInsensitiveText"
FROM "SomeEntities" AS s
WHERE right(@param, length(s."CaseInsensitiveText"))::citext = s."CaseInsensitiveText"
WHERE right(@param, length(s."CaseInsensitiveText")) = s."CaseInsensitiveText"
LIMIT 2
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public override async Task Sign()
"""
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 sign(b."Double")::int > 0
WHERE sign(b."Double") > 0
""");
}

Expand All @@ -438,7 +438,7 @@ public override async Task Sign_float()
"""
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 sign(b."Float")::int > 0
WHERE sign(b."Float") > 0
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,64 +109,64 @@ public override async Task Convert_ToInt32()
await base.Convert_ToInt32();

AssertSql(
"""
"""
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 b."Bool"::int = 1
""",
//
"""
//
"""
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 b."Byte"::int = 12
""",
//
"""
//
"""
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 b."Decimal"::int = 12
""",
//
"""
//
"""
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 b."Double"::int = 12
""",
//
"""
//
"""
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 b."Float"::int = 12
""",
//
"""
//
"""
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 b."Short"::int = 12
""",
//
"""
//
"""
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 b."Int"::int = 12
WHERE b."Int" = 12
""",
//
"""
//
"""
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 b."Long"::int = 12
""",
//
"""
//
"""
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 b."Int"::text::int = 12
""",
//
"""
//
"""
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 b."Int"::int = 12
WHERE b."Int" = 12
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ await AssertQuery(
"""
SELECT n."Id", n."DateInterval", n."Duration", n."Instant", n."InstantRange", n."Interval", n."LocalDate", n."LocalDate2", n."LocalDateRange", n."LocalDateTime", n."LocalTime", n."Long", n."OffsetTime", n."Period", n."TimeZoneId", n."ZonedDateTime"
FROM "NodaTimeTypes" AS n
WHERE n."Instant"::timestamptz = TIMESTAMPTZ '2018-04-20T10:31:33.666Z'
WHERE n."Instant" = TIMESTAMPTZ '2018-04-20T10:31:33.666Z'
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override async Task AddYears()
"""
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 CAST(b."DateOnly" + INTERVAL '3 years' AS date) = DATE '1993-11-10'
WHERE b."DateOnly" + INTERVAL '3 years' = DATE '1993-11-10'
""");
}

Expand All @@ -101,7 +101,7 @@ public override async Task AddMonths()
"""
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 CAST(b."DateOnly" + INTERVAL '3 months' AS date) = DATE '1991-02-10'
WHERE b."DateOnly" + INTERVAL '3 months' = DATE '1991-02-10'
""");
}

Expand Down Expand Up @@ -213,7 +213,7 @@ public override async Task ToDateTime_with_complex_DateTime()
"""
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 CAST(b."DateOnly" + INTERVAL '1 years' AS date) + b."TimeOnly" = TIMESTAMP '2021-01-01T15:30:10'
WHERE b."DateOnly" + INTERVAL '1 years' + b."TimeOnly" = TIMESTAMP '2021-01-01T15:30:10'
""");
}

Expand Down
Loading