Postgresql 所有查询都在Ecto中
我需要将下面的SQL转换为Ecto查询DSLPostgresql 所有查询都在Ecto中,postgresql,elixir,ecto,Postgresql,Elixir,Ecto,我需要将下面的SQL转换为Ecto查询DSL SELECT otc.* FROM users u INNER JOIN one_time_codes otc ON u.id = otc.user_id LEFT OUTER JOIN one_time_code_invalidations otci ON otci.one_time_code_id = otc.id WHERE u.id = 3 AND otc.code = 482693 AND otci.inserted
SELECT otc.*
FROM users u
INNER JOIN one_time_codes otc ON u.id = otc.user_id
LEFT OUTER JOIN one_time_code_invalidations otci ON otci.one_time_code_id = otc.id
WHERE u.id = 3 AND
otc.code = 482693 AND
otci.inserted_at IS NULL AND
otc.inserted_at > all(SELECT otc.inserted_at
FROM one_time_codes otc2
WHERE otc2.user_id = 3) AND
otc.inserted_at > (now() - '180 seconds'::interval);
在WHERE
子句的第三个和语句中,注意有一个ALL
查询。在exto.Query.API
中,似乎没有相应的函数
如何应用这种聚合?正确的实现方法是什么?尽管可以通过查找EXTO的调试日志来实现,但您还有其他想法(或建议)吗
谢谢。EXTO不允许在表达式中使用子查询,您是对的,在EXTO的查询API中没有all
,但您可以像这样使用fragment
:
where: ...
and otc.inserted_at > fragment("all(SELECT otc.inserted_at FROM one_time_codes otc2 WHERE otc2.user_id = ?", 3)
and ...
再次感谢:)。如何在片段中传递superquery参数,例如,您需要从superquery中找到的联接查询中引用用户中的u
?类似的操作对您有用吗:join:u in User,…,其中:fragment(“?=?”,u.id,10)
?哇,太好了。非常感谢。