fix #451
This commit is contained in:
parent
6b015400ed
commit
d17d44ffcf
2 changed files with 52 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# Changes
|
||||
|
||||
* 2.4.next in progress
|
||||
* Address [#451](https://github.com/seancorfield/honeysql/issues/451) by adding a test for it, showing how `:nest` produces the desired result.
|
||||
* Address [#447](https://github.com/seancorfield/honeysql/issues/447) by updating GitHub Actions and dependencies.
|
||||
* Address [#445](https://github.com/seancorfield/honeysql/issues/445) and [#453](https://github.com/seancorfield/honeysql/issues/453) by adding key/constraint examples to `CREATE TABLE` docs.
|
||||
|
||||
|
|
|
|||
51
test/honey/union_test.cljc
Normal file
51
test/honey/union_test.cljc
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
;; copyright (c) 2023 sean corfield, all rights reserved
|
||||
|
||||
(ns honey.union-test
|
||||
(:refer-clojure :exclude [format])
|
||||
(:require [clojure.test :refer [deftest is]]
|
||||
[honey.sql :as sut]))
|
||||
|
||||
(deftest issue-451
|
||||
(is (= [(str "SELECT ids.id AS id"
|
||||
" FROM ((SELECT dimension.human_readable_field_id AS id"
|
||||
" FROM dimension AS dimension"
|
||||
" WHERE (dimension.field_id = ?) AND (dimension.human_readable_field_id IS NOT NULL)"
|
||||
" LIMIT ?)"
|
||||
" UNION"
|
||||
" (SELECT dest.id AS id"
|
||||
" FROM field AS source"
|
||||
" LEFT JOIN table AS table ON source.table_id = table.id"
|
||||
" LEFT JOIN field AS dest ON dest.table_id = table.id"
|
||||
" WHERE (source.id = ?) AND (source.semantic_type IN (?)) AND (dest.semantic_type IN (?))"
|
||||
" LIMIT ?)) AS ids"
|
||||
" LIMIT ?")
|
||||
1
|
||||
1
|
||||
1
|
||||
"type/PK"
|
||||
"type/Name"
|
||||
1
|
||||
1]
|
||||
(-> {:select [[:ids.id :id]]
|
||||
:from [[{:union
|
||||
[{:nest
|
||||
{:select [[:dimension.human_readable_field_id :id]]
|
||||
:from [[:dimension :dimension]]
|
||||
:where [:and
|
||||
[:= :dimension.field_id 1]
|
||||
[:not= :dimension.human_readable_field_id nil]]
|
||||
:limit 1}}
|
||||
{:nest
|
||||
{:select [[:dest.id :id]]
|
||||
:from [[:field :source]]
|
||||
:left-join [[:table :table] [:= :source.table_id :table.id] [:field :dest] [:= :dest.table_id :table.id]]
|
||||
:where [:and
|
||||
[:= :source.id 1]
|
||||
[:in :source.semantic_type #{"type/PK"}]
|
||||
[:in :dest.semantic_type #{"type/Name"}]]
|
||||
:limit 1}}]}
|
||||
:ids]]
|
||||
:limit 1}
|
||||
(sut/format))))
|
||||
|
||||
)
|
||||
Loading…
Reference in a new issue