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
Postgresql 如何在EXTO FRAGENT语句中使用带时区的date_trunc_Postgresql_Elixir_Ecto - Fatal编程技术网

Postgresql 如何在EXTO FRAGENT语句中使用带时区的date_trunc

Postgresql 如何在EXTO FRAGENT语句中使用带时区的date_trunc,postgresql,elixir,ecto,Postgresql,Elixir,Ecto,我正在尝试查询商店的订单,并使用商店的时区查询其插入的日期 以下措施奏效了 shop |> Ecto.assoc(:orders) |> select([o], fragment("date_trunc('day', ? at time zone 'America/Los_Angeles')", o.inserted_at)) |> Repo.all 但是,当我尝试动态传递时区时,即使我显式地使用type将时区转换为字符串,也会出现“无法确定参数$1的数据类型”错误 shop

我正在尝试查询商店的订单,并使用商店的时区查询其
插入的
日期

以下措施奏效了

shop |> Ecto.assoc(:orders) |> select([o], fragment("date_trunc('day', ? at time zone 'America/Los_Angeles')", o.inserted_at)) |> Repo.all
但是,当我尝试动态传递时区时,即使我显式地使用
type
将时区转换为字符串,也会出现“无法确定参数$1的数据类型”错误

shop |> Ecto.assoc(:orders) |> select([o], fragment("date_trunc('day', ? at time zone '?')", o.inserted_at, type(^timezone, :string))) |> Repo.all


** (Postgrex.Error) ERROR 42P18 (indeterminate_datatype): could not determine data type of parameter $1
[debug] QUERY ERROR source="orders" db=1.0ms
SELECT date_trunc('day', o0."inserted_at" at time zone '$1::varchar') FROM "orders" AS o0 WHERE (o0."shop_id" = $2) ["America/Los_Angeles", "QXJnQWw2NWxhS289"]
    (ecto) lib/ecto/adapters/sql.ex:436: Ecto.Adapters.SQL.execute_and_cache/7
    (ecto) lib/ecto/repo/queryable.ex:130: Ecto.Repo.Queryable.execute/5
    (ecto) lib/ecto/repo/queryable.ex:35: Ecto.Repo.Queryable.all/4
在这里使用elixir 1.4.1和Exto 2.1.4

如何获得正确的查询


提前谢谢

在使用
片段时,您不需要在SQL中使用引号(
)(在修复引号错误后,也不需要显式类型转换):


使用
fragment
时,在SQL中不需要引号(
)(在修复引号错误后,也不需要显式类型转换):


尝试删除时区的
周围的单个引号:
片段(“日期('day',?在时区?),…)
@Dogbert成功了!谢谢尝试删除时区的
周围的单个引号:
片段(“日期('day',?在时区?),…)
@Dogbert成功了!谢谢
shop |> Ecto.assoc(:orders) |> select([o], fragment("date_trunc('day', ? at time zone ?)", o.inserted_at, ^timezone)) |> Repo.all