Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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:检查postgresql映射列是否有键_Postgresql_Elixir_Ecto - Fatal编程技术网

Elixir-Exto:检查postgresql映射列是否有键

Elixir-Exto:检查postgresql映射列是否有键,postgresql,elixir,ecto,Postgresql,Elixir,Ecto,使用json/jsonb数据类型EXTO suggets 就我而言,我必须使用PostgreSQL?操作员查看地图是否有这样的键,但它会变成: where(events, [e], e.type == 1 and not fragment("???", e.qualifiers, "?", "2")) 当然,片段读取PostgreSQL?作为占位符。我怎样才能检查地图上是否有这样的钥匙?你需要从中间逃走吗?并将总共三个参数传递给fragment: 演示: 我不确定这是否在任何地方有记录,但我从

使用json/jsonb数据类型EXTO suggets

就我而言,我必须使用PostgreSQL?操作员查看地图是否有这样的键,但它会变成:

where(events, [e], e.type == 1 and not fragment("???", e.qualifiers, "?", "2"))

当然,片段读取PostgreSQL?作为占位符。我怎样才能检查地图上是否有这样的钥匙?

你需要从中间逃走吗?并将总共三个参数传递给fragment:

演示:


我不确定这是否在任何地方有记录,但我从测试中找到了这个方法。

是的,我也发现了,必须先升级EXTO才能使用它,你能解释一下为什么要使用双“\”?这是因为Elixir也使用\作为转义字符,所以我们需要双转义它以确保Postgres得到1\。您还可以使用~S:~S|?\??==?\?。
fragment("? \\? ?", e.qualifiers, "2")
iex(1)> MyApp.Repo.insert! %MyApp.Food{name: "Foo", meta: %{price: 1}}
iex(2)> MyApp.Repo.insert! %MyApp.Food{name: "Foo", meta: %{}}
iex(3)> MyApp.Repo.all from(f in MyApp.Food, where: fragment("? \\? ?", f.meta, "price"))
[debug] SELECT f0."id", f0."name", f0."meta", f0."inserted_at", f0."updated_at" FROM "foods" AS f0 WHERE (f0."meta" ? 'price') [] OK query=8.0ms
[%MyApp.Food{__meta__: #Ecto.Schema.Metadata<:loaded>, id: 1,
  inserted_at: #Ecto.DateTime<2016-06-19T03:51:40Z>, meta: %{"price" => 1},
  name: "Foo", updated_at: #Ecto.DateTime<2016-06-19T03:51:40Z>}]
iex(4)> MyApp.Repo.all from(f in MyApp.Food, where: fragment("? \\? ?", f.meta, "a"))
[debug] SELECT f0."id", f0."name", f0."meta", f0."inserted_at", f0."updated_at" FROM "foods" AS f0 WHERE (f0."meta" ? 'a') [] OK query=0.8ms
[]