From 9c29cb29ff621e2ba1ea6ff40a4c545ea3899903 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Mon, 4 Mar 2024 12:11:51 -0800 Subject: [PATCH] fix #524 by adding :nest example for :union Signed-off-by: Sean Corfield --- CHANGELOG.md | 1 + doc/clause-reference.md | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e7d93..5160fd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/doc/clause-reference.md b/doc/clause-reference.md index 2e3e0b8..7a55355 100644 --- a/doc/clause-reference.md +++ b/doc/clause-reference.md @@ -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