首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(Postgrex.Error)尝试查询时出现错误42P18 (indeterminate_datatype)。

(Postgrex.Error)尝试查询时出现错误42P18 (indeterminate_datatype)。
EN

Stack Overflow用户
提问于 2018-01-29 16:57:54
回答 1查看 719关注 0票数 0

我有一个查询函数,它给出utc_date_fromutc_date_to,并取total的和。

因为我需要显示本地日期,所以我在select中添加了time_period,这是本地日期。

代码语言:javascript
复制
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中工作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-29 17:21:50

有时https://hexdocs.pm/ecto/Ecto.Query.API.html#type/2无法确定数据类型,因此您可以手动提供time_period的数据类型,另请参阅Ecto

代码语言:javascript
复制
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()
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48497524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档