【发布时间】:2021-08-17 21:33:35
【问题描述】:
我正在尝试进行 Ecto 查询,在其中连接给定查询结果的名字和姓氏,然后使用查询字符串执行 ilike 搜索。例如,我可能想在数据库中搜索所有以“Bob J”开头的名字。目前,我的代码如下所示:
pending_result_custom_search = from result in pending_result_query,
where: ilike(fragment("CONCAT(?, '',?)", result.first_name, result.last_name), ^query)
(pending_result_query 是我正在编写的上一个查询)
这种方法不起作用,我继续得到一个空的查询集。如果我执行这样的查询
query = "Bob"
pending_result_custom_search = from result in pending_result_query,
where: ilike(fragment("CONCAT(?, '',?)", "%Bob%", ""), ^query)
我得到了正确的功能。
使第一种方法正常工作的正确语法是什么?
【问题讨论】: