Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 日期范围的EXTO查询_Elixir_Phoenix Framework_Ecto - Fatal编程技术网

Elixir 日期范围的EXTO查询

Elixir 日期范围的EXTO查询,elixir,phoenix-framework,ecto,Elixir,Phoenix Framework,Ecto,我必须根据模型中的时间戳查询日期范围。 到目前为止,我所尝试的是 str="2017-12-18" {:ok, ed}=Ecto.Date.cast(str) ed= ed |> Ecto.Date.from_erl |> NaiveDate.from_erl! Repo.all(from l in Log, where: l.inserted_at == ^ed) 然而,postgres中的日期以日期时间的形式出现,例如2017-12-18 19:58:01.414 但我只想查

我必须根据模型中的时间戳查询日期范围。 到目前为止,我所尝试的是

str="2017-12-18"
{:ok, ed}=Ecto.Date.cast(str)
ed= ed |> Ecto.Date.from_erl  |> NaiveDate.from_erl!
Repo.all(from l in Log, where: l.inserted_at == ^ed)
然而,postgres中的日期以日期时间的形式出现,例如2017-12-18 19:58:01.414

但我只想查询日期,而不是时间。但是,如果我使用
exto.DateTime
NaiveDateTime
并以字符串形式传递准确的日期时间,它就会工作。但我只想在日期上匹配。这怎么可能呢?
谢谢

您可以使用
片段将字段强制转换为日期,然后比较:

Repo.all(from l in Log, where: fragment("?::date", l.inserted_at) == ^ed)

您可以使用
片段将字段强制转换为日期,然后比较:

Repo.all(from l in Log, where: fragment("?::date", l.inserted_at) == ^ed)

ed |>exto.Date.from |>NaiveDate.from |erl不能是真正的代码,请更正问题。
ed |>exto.Date.from|erl |>NaiveDate.from|erl
不能是真正的代码,请更正问题。谢谢,我如何在无绑定操作中使用它?我不认为这可以通过无绑定查询实现,因为LHS是一个片段。谢谢,我如何在无绑定操作中使用它?我不认为这可以通过无绑定查询实现,因为LHS是一个片段。