fix #524 by adding :nest example for :union

Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
Sean Corfield 2024-03-04 12:11:51 -08:00
parent 51e64e1891
commit 9c29cb29ff
No known key found for this signature in database
2 changed files with 8 additions and 0 deletions

View file

@ -1,6 +1,7 @@
# Changes
* 2.5.next in progress
* Address [#524](https://github.com/seancorfield/honeysql/issues/524) by adding example of `{:nest ..}` in `:union` clause reference docs.
* Address [#523](https://github.com/seancorfield/honeysql/issues/523) by expanding examples in README **Functions** to show aliases.
* Address [#522](https://github.com/seancorfield/honeysql/issues/522) by supporting metadata on table specifications in `:from` and `:join` clauses to provide index hints (SQL Server).
* Address [#521](https://github.com/seancorfield/honeysql/issues/521) by adding initial experimental support for an XTDB dialect.

View file

@ -484,6 +484,13 @@ user=> (sql/format '{union [{select (id,status) from (table-a)}
> Note: different databases have different precedence rules for these set operations when used in combination -- you may need to use `:nest` to add `(` .. `)` in order to combine these operations in a single SQL statement, if the natural order produced by HoneySQL does not work "as expected" for your database.
```clojure
;; BigQuery requires UNION clauses be parenthesized:
user=> (sql/format '{union [{:nest {select (id,status) from (table-a)}}
{:nest {select (id,(event status) from (table-b))}}]})
["(SELECT id, status FROM table_a) UNION (SELECT id, event AS status, from, table_b)"]
```
## select, select-distinct, table
`:select` and `:select-distinct` expect a sequence of SQL entities (column names