How to select the value of this mathematical operation in Ecto query?

How to convert this PostgreSQL query to an Ecto piped select expression:

select CEIL ( CAST ( records."duration" AS DECIMAL ) / 60 ) from records
where "duration" is not null

Thank you.

Solved, the way to do it is using fragment.

2 Likes

and no code snippet?? :stuck_out_tongue_winking_eye:

@Christopher-Shea

Like this:

  Record
    |> select([record], %{
    total: fragment("sum(CEIL ( CAST (? AS DECIMAL ) /60 )) / 2", record.duration)
    })
    |> Repo.one
2 Likes