I have tried this code:
def my_func(params) do
...
|> select(
[l],
%{
date: fragment("date_trunc('?',?) as date",
^params.date_trunc_type,
l.inserted_at),
}
)
...
|> Repo.all()
end
But i’m stacked at this error:
** (Postgrex.Error) ERROR 42P18 (indeterminate_datatype) could not determine data type of parameter $1
query: SELECT date_trunc('$1',s0."inserted_at") as date...
My Modules:
defmodule Administration.Reports.Params do
...
alias Administration.Enum.DateTruncType
embedded_schema do
...
field :date_trunc_type, DateTruncType, default: :month
end
...
end
defmodule Administration.Enum.DateTruncType do
use EctoEnum,
hour: "hour",
day: "day",
month: "month",
year: "year"
end
I want to construct this sql’s SELECTs
SELECT date_trunc('hour', inserted_at)
SELECT date_trunc('day', inserted_at)
SELECT date_trunc('month', inserted_at)
SELECT date_trunc('year', inserted_at)






















