D.R*_*D.R 0 postgresql elixir ecto
我有一个查询函数,它给出utc_date_from和utc_date_to并取 的和total。
由于我需要提供本地日期,因此我将time_period本地日期添加到 中select。
time_period = to_string(date)
Payment
|> where([p], p.core_id == ^core_id and
p.inserted_at >= datetime_add(^utc_date_from, 0, "day") and
p.inserted_at <= datetime_add(^utc_date_to, 0, "day"))
|> select([p], %{amount: sum(p.total), time_period: ^time_period})
|> Repo.one()
Run Code Online (Sandbox Code Playgroud)
但是,如果我添加time_period到select,它会触发一个错误(Postgrex.Error) ERROR 42P18 (indeterminate_datatype): could not determine data type of parameter $1。
此外,此错误仅在我在 ubuntu 中运行我的应用程序时显示。如果我尝试使用 mac os,它不会显示此错误。
这个函数有什么问题吗?我怎样才能让它在ubuntu上工作?
有时 Ecto 无法确定数据类型,因此您可以手动提供 的数据类型time_period,另请参阅https://hexdocs.pm/ecto/Ecto.Query.API.html#type/2:
time_period = to_string(date)
Payment
|> where([p], p.core_id == ^core_id and
p.inserted_at >= datetime_add(^utc_date_from, 0, "day") and
p.inserted_at <= datetime_add(^utc_date_to, 0, "day"))
|> select([p], %{amount: sum(p.total), time_period: type(^time_period, :string)})
|> Repo.one()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1271 次 |
| 最近记录: |