在ecto我可以写
query = from q in CustomerModel, where: like(q.id, "%1")
#Ecto.Query<from c in Qber.V1.CustomerModel, where: like(c.id, "%1")>
当我运行此查询时,我得到了
(undefined_function): operator does not exist: integer ~~ unknown
来自question我认为在 ID 上应用赞之前我必须强制。所以在 Postgres 中,我可以简单地将此查询写为
SELECT * FROM customers WHERE CAST(id AS TEXT) LIKE '1%';
在应用赞?
之前,如何在ecto中应用强制转换?答案 0 :(得分:4)
您可以使用fragment
创建与您想要的查询相同的查询:
query =
from q in CustomerModel,
where: like(fragment("CAST(? AS TEXT)", q.id), "1%")