我是Postgresql JSONb和Ecto的新手。我有一个列“配置”的表,即jsonb。我能够插入,但是当我尝试使用where条件从它中选择片段函数时,我无法让它工作。下面是示例和输出:
iex> Repo.all(from i in Instance, select: i.configuration, where:
fragment("?->'testing' LIKE '%hey%'", i.configuration))
[debug] QUERY ERROR source="instances" db=0.4ms
SELECT i0."configuration" FROM "instances" AS i0 WHERE
(i0."configuration"->'testing' LIKE '%hey%') []
** (Postgrex.Error) ERROR 42883 (undefined_function): operator does not
exist: jsonb ~~ unknown
(ecto) lib/ecto/adapters/sql.ex:431:
Ecto.Adapters.SQL.execute_and_cache/7
(ecto) lib/ecto/repo/queryable.ex:133: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:37: Ecto.Repo.Queryable.all/4如果我以这样的方式执行原始查询:
iex> query = """
select configuration FROM instances where configuration->>'testing'
LIKE '%hey%'
"""
iex> Ecto.Adapters.SQL.query!(Repo, query)
[debug] QUERY OK db=1.0ms
select configuration FROM instances where configuration->>'testing'
LIKE '%hey%' []
%Postgrex.Result{columns: ["configuration"], command: :select,
connection_id: 28581, num_rows: 1, rows: [[%{"testing" => "some test
hey?"}]]}同样,在psql中,以下查询工作:
select configuration FROM instances where configuration->>'tsting' LIKE '%hey%';关于我在Repo.all上做错什么的任何帮助(.查询将不胜感激,因为我已经尝试了一堆,但没有效果,不明白我做错了什么。
https://stackoverflow.com/questions/46417251
复制相似问题