我找不到如何在 rom-sql 中编写此查询。是否可以将纯sql添加到where
?
它查找与请求不相交的公告。
announcements.when
并且requests.when
是 postgres 中的 tstzrange 列。
SELECT "announcements".* FROM "announcements" WHERE (
(SELECT COUNT(requests.id)
FROM requests
WHERE requests.id IN (1,2,3) AND
(TSTZRANGE(lower(requests.when) - INTERVAL '1 HOUR', upper(requests.when) + INTERVAL '1 HOUR', '()') &&
TSTZRANGE(lower(announcements.when)), upper(announcements.when), '()') AND
requests.user_id = 42
) = 0
)