Fork me on GitHub
#honeysql
<
2024-02-07
>
Jo Øivind Gjernes15:02:14

I’m trying to write a query like:

(select * from table_1 limit 10 order by x) union all (select * from table_1b limit 10 order by x) limit 10 order by x
but am not able to get honey to “group” the selects in parens so i can get limit applied before and after the union I made it work using CTEs, but that should not really be necessary

p-himik15:02:53

(sql/format {:union-all [{:nest {:select :*}}
                         {:nest {:select :*}}]
             :limit     [:inline 10]})
=> ["(SELECT *) UNION ALL (SELECT *) LIMIT 10"]

Jo Øivind Gjernes15:02:04

facepalm i’ve tried nest but [:nest]

😄 1
Jo Øivind Gjernes15:02:59

This works, thanks a lot 🙂

👍 1
p-himik15:02:59

Yeah, I tried that at first too. :)

seancorfield18:02:31

Happy to update the docs to make that easier to figure out, if you have suggestions. The :union-all docs mention :nest https://cljdoc.org/d/com.github.seancorfield/honeysql/2.5.1103/doc/getting-started/sql-clause-reference#intersect-union-union-all-except-except-all (but don't provide an example).