From c2e8bb91936d14b09e16fb5332d02f084b147172 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Fri, 9 Apr 2021 17:48:13 -0700 Subject: [PATCH] Finish off the PostgreSQL comparison docs --- doc/clause-reference.md | 14 ++++++++++++-- doc/getting-started.md | 2 +- doc/postgresql.md | 20 ++++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/doc/clause-reference.md b/doc/clause-reference.md index 992a348..a51cc7c 100644 --- a/doc/clause-reference.md +++ b/doc/clause-reference.md @@ -629,14 +629,24 @@ user=> (sql/format {:select [:id :MaxSalary]]]] :from [:employee] :window [:w {:partition-by [:department]}]}) -["SELECT id, AVG(salary) OVER (PARTITION BY department ORDER BY designation ASC) AS Average, MAX(salary) OVER w AS MaxSalary FROM employee WINDOW w AS (PARTITION BY department)"] +;; newlines inserted for readability: +["SELECT id, + AVG(salary) OVER (PARTITION BY department ORDER BY designation ASC) AS Average, + MAX(salary) OVER w AS MaxSalary + FROM employee + WINDOW w AS (PARTITION BY department)"] ;; easier to write with helpers (and easier to read!): user=> (sql/format (-> (select :id (over [[:avg :salary] (-> (partition-by :department) (order-by :designation)) :Average] [[:max :salary] :w :MaxSalary])) (from :employee) (window :w (partition-by :department)))) -["SELECT id, AVG(salary) OVER (PARTITION BY department ORDER BY designation ASC) AS Average, MAX(salary) OVER w AS MaxSalary FROM employee WINDOW w AS (PARTITION BY department)"] +;; newlines inserted for readability: +["SELECT id, + AVG(salary) OVER (PARTITION BY department ORDER BY designation ASC) AS Average, + MAX(salary) OVER w AS MaxSalary + FROM employee + WINDOW w AS (PARTITION BY department)"] ``` The window function in the `:over` expression may be `{}` or `nil`: diff --git a/doc/getting-started.md b/doc/getting-started.md index 05f4326..74c83e4 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -190,7 +190,7 @@ There is a helper function for every single clause that HoneySQL supports out of the box. In addition, there are helpers for `composite`, `lateral`, `over`, and `upsert` that make it easier to construct those parts of the SQL DSL (examples of `composite` appear in the [README](README.md), -examples of `over` appear in the [Clause Reference](docs/clause-reference.md)) +examples of `over` appear in the [Clause Reference](clause-reference.md)) In addition to being variadic -- which often lets you omit one level of `[`..`]` -- the helper functions merge clauses, which diff --git a/doc/postgresql.md b/doc/postgresql.md index 2a9e535..8b4ceff 100644 --- a/doc/postgresql.md +++ b/doc/postgresql.md @@ -5,7 +5,7 @@ features that HoneySQL supports out of the box for which you previously needed the [nilenso/honeysql-postgres library](https://github.com/nilenso/honeysql-postgres). -Everything that the nilenso library provided is implemented +Everything that the nilenso library provided (in 0.3.104) is implemented directly in HoneySQL 2.x although a few things have a slightly different syntax. @@ -79,7 +79,7 @@ user=> (-> (insert-into :distributors) ``` `ON CONSTRAINT` is handled slightly differently to the nilenso library, -with provided a single `on-conflict-constraint` helper (and clause): +which provided a single `on-conflict-constraint` helper (and clause): ```clojure user=> (-> (insert-into :distributors) @@ -153,6 +153,18 @@ By comparison, this is the DSL structure that nilenso would have required: ## INSERT INTO AS +HoneySQL supports aliases directly in `:insert-into` so no special +clause is needed for this any more: + +```clojure +user=> (sql/format (-> (insert-into :table :alias) + (values [[1 2 3] [4 5 6]]))) +["INSERT INTO table AS alias VALUES (?, ?, ?), (?, ?, ?)" 1 2 3 4 5 6] +user=> (sql/format {:insert-into [:table :alias], + :values [[1 2 3] [4 5 6]]}) +["INSERT INTO table AS alias VALUES (?, ?, ?), (?, ?, ?)" 1 2 3 4 5 6] +``` + ## Returning The `RETURNING` clause is supported identically to the nilenso library: @@ -325,3 +337,7 @@ user=> (sql/format (alter-table :fruit ``` ## Window / Partition Support + +HoneySQL supports `:window`, `:partition-by`, and `:over` +directly now. +See the Clause Reference for examples of [WINDOW, PARTITION BY, and OVER](clause-reference.md#window-partition-by-and-over).