From 35545facced1030bfb349be706db0db7e9088e9b Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 13 Oct 2024 12:16:59 -0700 Subject: [PATCH] fixes #542 by documenting new clauses Signed-off-by: Sean Corfield --- CHANGELOG.md | 4 ++-- doc/clause-reference.md | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ed25c6..d67f7cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changes * 2.6.next in progress - * Fix [#548](https://github.com/seancorfield/honeysql/issues/548) which was a regression introduced in [#526](https://github.com/seancorfield/honeysql/issues/526). - * Address [#542](https://github.com/seancorfield/honeysql/issues/542) by adding support for `WITH` query tail options for PostgreSQL. Docs TBD. + * Fix [#548](https://github.com/seancorfield/honeysql/issues/548) which was a regression introduced in [#526](https://github.com/seancorfield/honeysql/issues/526) (in 2.6.1161). + * Address [#542](https://github.com/seancorfield/honeysql/issues/542) by adding support for `WITH` query tail options for PostgreSQL. * Replace all optional argument destructuring with multiple arities to improve performance. * 2.6.1196 -- 2024-10-06 diff --git a/doc/clause-reference.md b/doc/clause-reference.md index 26a1b74..d7cc23f 100644 --- a/doc/clause-reference.md +++ b/doc/clause-reference.md @@ -486,6 +486,27 @@ user=> (sql/format {:with [[:stuff {:select :* ["WITH stuff AS NOT MATERIALIZED (SELECT * FROM table) SELECT * FROM stuff"] ``` +As of 2.6.next, you can specify `SEARCH` and/or `CYCLE` clauses, in place of +or following the `MATERIALIZED` marker: + +```clojure +user=> (sql/format {:with-recursive [[:stuff {:select :* + :from :table} + :search-depth-first-by :col :set :search-col]] + :select :* + :from :stuff}) +["WITH RECURSIVE stuff AS (SELECT * FROM table) SEARCH DEPTH FIRST BY col SET search_col SELECT * FROM stuff"] +``` + +```clojure +user=> (sql/format {:with-recursive [[:stuff {:select :* + :from :table} + :cycle [:a :b :c] :set :d :to [:abs :e] :default 42 :using :x]] + :select :* + :from :stuff}) +["WITH RECURSIVE stuff AS (SELECT * FROM table) CYCLE a, b, c SET d TO ABS(e) DEFAULT ? USING x SELECT * FROM stuff" 42] +``` + `:with-recursive` follows the same rules as `:with` and produces `WITH RECURSIVE` instead of just `WITH`. ## intersect, union, union-all, except, except-all