Skip to content

Commit af7ed51

Browse files
committed
fix: ensure that decimal-producing calculations cast args as decimals
1 parent a80ce0f commit af7ed51

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

lib/expr.ex

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,14 +1174,23 @@ defmodule AshSql.Expr do
11741174
:/ ->
11751175
{types, result} = determine_types(bindings.sql_behaviour, mod, [left, right], type)
11761176

1177-
{Enum.map(types, fn
1178-
{Ash.Type.Float, _} -> {Ash.Type.Decimal, []}
1179-
other -> other
1180-
end),
1181-
case result do
1182-
{Ash.Type.Float, _} -> {Ash.Type.Decimal, []}
1183-
other -> other
1184-
end}
1177+
{types, result} =
1178+
{Enum.map(types, fn
1179+
{Ash.Type.Float, _} -> {Ash.Type.Decimal, []}
1180+
other -> other
1181+
end),
1182+
case result do
1183+
{Ash.Type.Float, _} -> {Ash.Type.Decimal, []}
1184+
other -> other
1185+
end}
1186+
1187+
case result do
1188+
{Ash.Type.Decimal, _} ->
1189+
{Enum.map(types, fn _ -> {Ash.Type.Decimal, []} end), result}
1190+
1191+
_ ->
1192+
{types, result}
1193+
end
11851194

11861195
_ ->
11871196
determine_types(bindings.sql_behaviour, mod, [left, right], type)

0 commit comments

Comments
 (0)