Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{:deps {honeysql {:mvn/version "0.9.4" :exclusions [org.clojure/clojurescript]}}}
{:deps {honeysql {:mvn/version "0.9.5" :exclusions [org.clojure/clojurescript]}}}
5 changes: 4 additions & 1 deletion src/honeysql_postgres/format.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns ^{:doc "Extension of the honeysql format functions specifically for postgreSQL"}
honeysql-postgres.format
(:require [honeysql.format :as sqlf :refer [fn-handler format-clause]] ;; multi-methods
(:require [honeysql.format :as sqlf :refer [fn-handler format-clause format-modifiers]] ;; multi-methods
[honeysql-postgres.util :as util]
[clojure.string :as string]))

Expand Down Expand Up @@ -220,3 +220,6 @@
(string/join " EXCEPT ALL " (map sqlf/to-sql maps))))

(override-default-clause-priority)

(defmethod format-modifiers :distinct-on [[_ & fields]]
(str "DISTINCT ON(" (sqlf/comma-join (map sqlf/to-sql fields)) ")"))
11 changes: 10 additions & 1 deletion test/honeysql_postgres/postgres_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
create-table rename-table drop-table
window create-view over with-columns]]
[honeysql.helpers :as sqlh :refer [insert-into values where select columns
from order-by update sset query-values]]
from order-by update sset query-values
modifiers]]
[honeysql.core :as sql]
[clojure.test :as test :refer [deftest is testing]]))

Expand Down Expand Up @@ -254,3 +255,11 @@
{:except-all
[{:select [:ip]}
{:select [:ip] :from [:ip_location]}]})))))

(deftest select-distinct-on
(testing "select distinct on"
(is (= ["SELECT DISTINCT ON(\"a\", \"b\") \"c\" FROM \"products\" "]
(-> (select :c)
(from :products)
(modifiers :distinct-on :a :b)
(sql/format :quoting :ansi))))))