我有一个查询函数,它给出utc_date_from和utc_date_to,并取total的和。
因为我需要显示本地日期,所以我在select中添加了time_period,这是本地日期。
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()但是,如果我将time_period添加到select中,则会触发(Postgrex.Error) ERROR 42P18 (indeterminate_datatype): could not determine data type of parameter $1错误。
此外,此错误仅在我在ubuntu中运行应用程序时显示。如果我尝试使用mac os,它不会显示此错误。
这个函数有什么问题?我怎样才能让它在ubuntu中工作?
发布于 2018-01-29 17:21:50
有时https://hexdocs.pm/ecto/Ecto.Query.API.html#type/2无法确定数据类型,因此您可以手动提供time_period的数据类型,另请参阅Ecto
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()https://stackoverflow.com/questions/48497524
复制相似问题