From 37fe8b21bc69ed124a39541bc015412e54d0117d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=20=C3=98ivind=20Gjernes?= Date: Thu, 12 Sep 2024 08:59:48 +0200 Subject: [PATCH] additional docs for cte a small example was added to illustrate how to specify a Common Table Expression (CTE) as materialized or not materialized. --- doc/clause-reference.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/clause-reference.md b/doc/clause-reference.md index d729d1b..2eb464c 100644 --- a/doc/clause-reference.md +++ b/doc/clause-reference.md @@ -476,6 +476,16 @@ user=> (sql/format {:with [[[:stuff {:columns [:id :name]}] > Note: you must use the vector-of-vectors format for `:values` here -- if you try to use the vector-of-maps format, `VALUES` will be preceded by the column names (keys from the maps) and the resultant SQL will be invalid. +You can specify `MATERIALIZED`, `NOT MATERIALIZED` for the CTE: + +```clojure +user=> (sql/format {:with [[:stuff {:select :* + :from :table} :not-materialized]] + :select :* + :from :stuff}) +["WITH stuff AS NOT MATERIALIZED (SELECT * FROM table) SELECT * FROM stuff"] +``` + `:with-recursive` follows the same rules as `:with` and produces `WITH RECURSIVE` instead of just `WITH`. ## intersect, union, union-all, except, except-all