honeysql

Jo Øivind Gjernes 2024-02-07T15:00:14.881789Z

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-himik 2024-02-07T15:25:53.014119Z

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

Jo Øivind Gjernes 2024-02-07T15:27:04.130029Z

facepalm i’ve tried nest but [:nest]

😄 1
Jo Øivind Gjernes 2024-02-07T15:27:59.859479Z

This works, thanks a lot 🙂

👍 1
p-himik 2024-02-07T15:27:59.969769Z

Yeah, I tried that at first too. :)

seancorfield 2024-02-07T18:03:31.255949Z

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).

seancorfield 2024-02-07T18:04:35.125419Z

https://github.com/seancorfield/honeysql/issues/524

2024-02-07T18:04:29.556159Z

2024-03-04T20:52:30.276209Z