Skip to content

Commit d9a236c

Browse files
authored
Change upper/lower case to align with PG conventions (#2397)
1 parent 28999d5 commit d9a236c

32 files changed

+590
-590
lines changed

src/EFCore.PG.NodaTime/Query/Internal/NpgsqlNodaTimeMemberTranslatorPlugin.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ SqlExpression Upper()
297297

298298
case "DayOfWeek":
299299
// Unlike DateTime.DayOfWeek, NodaTime's IsoDayOfWeek enum doesn't exactly correspond to PostgreSQL's
300-
// values returned by DATE_PART('dow', ...): in NodaTime Sunday is 7 and not 0, which is None.
300+
// values returned by date_part('dow', ...): in NodaTime Sunday is 7 and not 0, which is None.
301301
// So we generate a CASE WHEN expression to translate PostgreSQL's 0 to 7.
302302
var getValueExpression = GetDatePartExpression(instance, "dow", true);
303303
// TODO: Can be simplified once https://github.com/aspnet/EntityFrameworkCore/pull/16726 is in
@@ -331,16 +331,16 @@ SqlExpression Upper()
331331
}
332332

333333
/// <summary>
334-
/// Constructs the DATE_PART expression.
334+
/// Constructs the date_part expression.
335335
/// </summary>
336336
/// <param name="e">The member expression.</param>
337-
/// <param name="partName">The name of the DATE_PART to construct.</param>
338-
/// <param name="floor">True if the result should be wrapped with FLOOR(...); otherwise, false.</param>
337+
/// <param name="partName">The name of the date_part to construct.</param>
338+
/// <param name="floor">True if the result should be wrapped with floor(...); otherwise, false.</param>
339339
/// <returns>
340-
/// The DATE_PART expression.
340+
/// The date_part expression.
341341
/// </returns>
342342
/// <remarks>
343-
/// DATE_PART returns doubles, which we floor and cast into ints
343+
/// date_part returns doubles, which we floor and cast into ints
344344
/// This also gets rid of sub-second components when retrieving seconds.
345345
/// </remarks>
346346
private SqlExpression GetDatePartExpression(
@@ -358,7 +358,7 @@ private SqlExpression GetDatePartExpressionDouble(
358358
bool floor = false)
359359
{
360360
var result = _sqlExpressionFactory.Function(
361-
"DATE_PART",
361+
"date_part",
362362
new[] { _sqlExpressionFactory.Constant(partName), instance },
363363
nullable: true,
364364
argumentsPropagateNullability: TrueArrays[2],
@@ -367,7 +367,7 @@ private SqlExpression GetDatePartExpressionDouble(
367367
if (floor)
368368
{
369369
result = _sqlExpressionFactory.Function(
370-
"FLOOR",
370+
"floor",
371371
new[] { result },
372372
nullable: true,
373373
argumentsPropagateNullability: TrueArrays[1],

src/EFCore.PG.NodaTime/Query/Internal/NpgsqlNodaTimeMethodCallTranslatorPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public NpgsqlNodaTimeMethodCallTranslator(
226226

227227
static PostgresFunctionExpression IntervalPart(string datePart, SqlExpression parameter)
228228
=> PostgresFunctionExpression.CreateWithNamedArguments(
229-
"MAKE_INTERVAL",
229+
"make_interval",
230230
new[] { parameter },
231231
new[] { datePart },
232232
nullable: true,

src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMathTranslator.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,24 @@ public class NpgsqlMathTranslator : IMethodCallTranslator
7272
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Tan), new[] { typeof(float) })!, "tan" },
7373

7474
// https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
75-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(decimal), typeof(decimal) })!, "greatest" },
76-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(double), typeof(double) })!, "greatest" },
77-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(float), typeof(float) })!, "greatest" },
78-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(int), typeof(int) })!, "greatest" },
79-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(long), typeof(long) })!, "greatest" },
80-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(short), typeof(short) })!, "greatest" },
81-
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Max), new[] { typeof(float), typeof(float) })!, "greatest" },
82-
{ typeof(BigInteger).GetRuntimeMethod(nameof(BigInteger.Max), new[] { typeof(BigInteger), typeof(BigInteger) })!, "greatest" },
75+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(decimal), typeof(decimal) })!, "GREATEST" },
76+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(double), typeof(double) })!, "GREATEST" },
77+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(float), typeof(float) })!, "GREATEST" },
78+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(int), typeof(int) })!, "GREATEST" },
79+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(long), typeof(long) })!, "GREATEST" },
80+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Max), new[] { typeof(short), typeof(short) })!, "GREATEST" },
81+
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Max), new[] { typeof(float), typeof(float) })!, "GREATEST" },
82+
{ typeof(BigInteger).GetRuntimeMethod(nameof(BigInteger.Max), new[] { typeof(BigInteger), typeof(BigInteger) })!, "GREATEST" },
8383

8484
// https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
85-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(decimal), typeof(decimal) })!, "least" },
86-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(double), typeof(double) })!, "least" },
87-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(float), typeof(float) })!, "least" },
88-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(int), typeof(int) })!, "least" },
89-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(long), typeof(long) })!, "least" },
90-
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(short), typeof(short) })!, "least" },
91-
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Min), new[] { typeof(float), typeof(float) })!, "least" },
92-
{ typeof(BigInteger).GetRuntimeMethod(nameof(BigInteger.Min), new[] { typeof(BigInteger), typeof(BigInteger) })!, "least" },
85+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(decimal), typeof(decimal) })!, "LEAST" },
86+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(double), typeof(double) })!, "LEAST" },
87+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(float), typeof(float) })!, "LEAST" },
88+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(int), typeof(int) })!, "LEAST" },
89+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(long), typeof(long) })!, "LEAST" },
90+
{ typeof(Math).GetRuntimeMethod(nameof(Math.Min), new[] { typeof(short), typeof(short) })!, "LEAST" },
91+
{ typeof(MathF).GetRuntimeMethod(nameof(MathF.Min), new[] { typeof(float), typeof(float) })!, "LEAST" },
92+
{ typeof(BigInteger).GetRuntimeMethod(nameof(BigInteger.Min), new[] { typeof(BigInteger), typeof(BigInteger) })!, "LEAST" },
9393
};
9494

9595
private static readonly IEnumerable<MethodInfo> TruncateMethodInfos = new[]

src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ public NpgsqlNetworkTranslator(
8383
nameof(NpgsqlNetworkDbFunctionsExtensions.ContainsOrContainedBy)
8484
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.NetworkContainsOrContainedBy, arguments[1], arguments[2]),
8585

86-
nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseNot) => new SqlUnaryExpression(ExpressionType.Not,
87-
arguments[1],
88-
arguments[1].Type,
89-
arguments[1].TypeMapping),
86+
nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseNot)
87+
=> new SqlUnaryExpression(ExpressionType.Not, arguments[1], arguments[1].Type, arguments[1].TypeMapping),
9088

91-
nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseAnd) => _sqlExpressionFactory.And(arguments[1], arguments[2]),
92-
nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseOr) => _sqlExpressionFactory.Or(arguments[1], arguments[2]),
89+
nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseAnd)
90+
=> _sqlExpressionFactory.And(arguments[1], arguments[2]),
91+
nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseOr)
92+
=> _sqlExpressionFactory.Or(arguments[1], arguments[2]),
9393

9494
// Add/Subtract accept inet + int, so we can't use the default type mapping inference logic which assumes
9595
// same-typed operands

src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlQueryableAggregateMethodTranslator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
4343
return averageInputType == typeof(float)
4444
? _sqlExpressionFactory.Convert(
4545
_sqlExpressionFactory.AggregateFunction(
46-
"AVG",
46+
"avg",
4747
new[] { averageSqlExpression },
4848
nullable: true,
4949
argumentsPropagateNullability: FalseArrays[1],
@@ -52,7 +52,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
5252
averageSqlExpression.Type,
5353
averageSqlExpression.TypeMapping)
5454
: _sqlExpressionFactory.AggregateFunction(
55-
"AVG",
55+
"avg",
5656
new[] { averageSqlExpression },
5757
nullable: true,
5858
argumentsPropagateNullability: FalseArrays[1],
@@ -68,7 +68,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
6868
return _sqlExpressionFactory.Convert(
6969
_sqlExpressionFactory.ApplyDefaultTypeMapping(
7070
_sqlExpressionFactory.AggregateFunction(
71-
"COUNT",
71+
"count",
7272
new[] { countSqlExpression },
7373
nullable: false,
7474
argumentsPropagateNullability: FalseArrays[1],
@@ -82,7 +82,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
8282
var longCountSqlExpression = (source.Selector as SqlExpression) ?? _sqlExpressionFactory.Fragment("*");
8383
return _sqlExpressionFactory.ApplyDefaultTypeMapping(
8484
_sqlExpressionFactory.AggregateFunction(
85-
"COUNT",
85+
"count",
8686
new[] { longCountSqlExpression },
8787
nullable: false,
8888
argumentsPropagateNullability: FalseArrays[1],
@@ -94,7 +94,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
9494
|| methodInfo == QueryableMethods.MaxWithSelector)
9595
&& source.Selector is SqlExpression maxSqlExpression:
9696
return _sqlExpressionFactory.AggregateFunction(
97-
"MAX",
97+
"max",
9898
new[] { maxSqlExpression },
9999
nullable: true,
100100
argumentsPropagateNullability: FalseArrays[1],
@@ -107,7 +107,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
107107
|| methodInfo == QueryableMethods.MinWithSelector)
108108
&& source.Selector is SqlExpression minSqlExpression:
109109
return _sqlExpressionFactory.AggregateFunction(
110-
"MIN",
110+
"min",
111111
new[] { minSqlExpression },
112112
nullable: true,
113113
argumentsPropagateNullability: FalseArrays[1],
@@ -129,7 +129,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
129129
{
130130
return _sqlExpressionFactory.Convert(
131131
_sqlExpressionFactory.AggregateFunction(
132-
"SUM",
132+
"sum",
133133
new[] { sumSqlExpression },
134134
nullable: true,
135135
argumentsPropagateNullability: FalseArrays[1],
@@ -143,7 +143,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
143143
{
144144
return _sqlExpressionFactory.Convert(
145145
_sqlExpressionFactory.AggregateFunction(
146-
"SUM",
146+
"sum",
147147
new[] { sumSqlExpression },
148148
nullable: true,
149149
argumentsPropagateNullability: FalseArrays[1],
@@ -154,7 +154,7 @@ public NpgsqlQueryableAggregateMethodTranslator(
154154
}
155155

156156
return _sqlExpressionFactory.AggregateFunction(
157-
"SUM",
157+
"sum",
158158
new[] { sumSqlExpression },
159159
nullable: true,
160160
argumentsPropagateNullability: FalseArrays[1],

src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public NpgsqlStringMethodTranslator(
6969
_whitespace = _sqlExpressionFactory.Constant(
7070
@" \t\n\r", // TODO: Complete this
7171
typeMappingSource.EStringTypeMapping);
72-
_textTypeMapping = (RelationalTypeMapping)typeMappingSource.FindMapping(typeof(string), model)!;
72+
_textTypeMapping = typeMappingSource.FindMapping(typeof(string), model)!;
7373
}
7474

7575
public virtual SqlExpression? Translate(

src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio
362362
case ScalarSubqueryExpression:
363363
var storeType = sqlUnaryExpression.TypeMapping.StoreType switch
364364
{
365-
"integer" => "INT",
365+
"integer" => "int",
366366
"timestamp with time zone" => "timestamptz",
367367
"timestamp without time zone" => "timestamp",
368368
var s => s
@@ -631,7 +631,7 @@ public virtual Expression VisitJsonPathTraversal(PostgresJsonTraversalExpression
631631
Sql.Append(",");
632632
}
633633
}
634-
Sql.Append("]::TEXT[]");
634+
Sql.Append("]::text[]");
635635
}
636636

637637
return expression;

src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
317317
ExpressionType.Subtract, sqlLeft!, sqlRight!, _typeMappingSource.FindMapping(typeof(int)))!;
318318

319319
return PostgresFunctionExpression.CreateWithNamedArguments(
320-
"MAKE_INTERVAL",
320+
"make_interval",
321321
new[] { subtraction },
322322
new[] { "days" },
323323
nullable: true,

test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,13 +912,13 @@ public void Sum_Conversions()
912912
_ = context.Set<MappedDataTypes>().Sum(m => m.ShortAsSmallint);
913913

914914
AssertSql(
915-
@"SELECT COALESCE(SUM(m.""LongAsBigint""), 0.0)::bigint
915+
@"SELECT COALESCE(sum(m.""LongAsBigint""), 0.0)::bigint
916916
FROM ""MappedDataTypes"" AS m",
917917
//
918-
@"SELECT COALESCE(SUM(m.""Int""), 0)::int
918+
@"SELECT COALESCE(sum(m.""Int""), 0)::int
919919
FROM ""MappedDataTypes"" AS m",
920920
//
921-
@"SELECT COALESCE(SUM(m.""ShortAsSmallint""::INT), 0)::INT
921+
@"SELECT COALESCE(sum(m.""ShortAsSmallint""::int), 0)::int
922922
FROM ""MappedDataTypes"" AS m");
923923
}
924924

0 commit comments

Comments
 (0)