我正在尝试使用 clsql:select 函数创建子查询:
CL-USER> (select [books.bookid]
:from [books]
:where
(sql-in [books.bookid]
(select [bookid]
:from [bookauthors]
:where
(sql-= [bookauthors.authorid] 120))))
;; 2015-03-07T06:37:08 /books/ => SELECT BOOKID FROM BOOKAUTHORS WHERE (BOOKAUTHORS.AUTHORID = 120)
;; 2015-03-07T06:37:08 /books/ => SELECT BOOKS.BOOKID FROM BOOKS WHERE (BOOKS.BOOKID IN ((157)))
((157))
("bookid")
它可以工作,但不是使用子选择子句生成一个查询,而是 clsql 运行两个查询。这不会像让 postgresql 后端处理整个事情那样有效。
CL-USER> (clsql-sys:db-type-has-subqueries? :postgresql)
T
显然 postgresql 连接器支持子查询。有没有办法让选择函数来生成它们?