【发布时间】:2015-04-02 15:49:05
【问题描述】:
我在玩 Elixir&Ecto 的东西。我想创建自定义 SQL 查询,它使用一些 postgres 特定的功能(在本例中:它搜索 postgres 数组)。
这是我想要做的:
iex(5)> query = from g in MyModel, where: "'sample_tag' = ANY(tags)", select: g #Ecto.Query<from g in MyModel, where: "'sample_tag' = ANY(tags)", select: g>
iex(6)> Repo.all(query) [debug] SELECT g0."id", g0."name", g0."description", g0."image_file_name", g0."image_file_size", g0."image_updated_at", g0."image_content_type" FROM "my_model" AS g0 WHERE ('''sample_tag'' = ANY(tags)') [] (0.9ms)
不幸的是,它被转义了(所以它应该产生这样的东西:)
SELECT g0."id", g0."name", g0."description", g0."image_file_name", g0."image_file_size", g0."image_updated_at", g0."image_content_type" FROM "my_mode." AS g0 WHERE ('sample_tag' = ANY(tags))
我怎样才能做到这一点?
【问题讨论】: