Back
bulk-collect-into (clj)
(source)function
(bulk-collect-into varname)
(bulk-collect-into varname n)
Accepts a variable name, optionally followed by a limit
expression.
Examples
honeysql
(ns honey.sql.helpers-test
(:refer-clojure :exclude [filter for group-by partition-by set update])
(:require [clojure.test :refer [deftest is testing]]
[honey.sql :as sql]
[honey.sql.helpers :as h
:refer [add-column add-index alter-table columns create-table create-table-as create-view
create-materialized-view drop-view drop-materialized-view
create-index
bulk-collect-into
cross-join do-update-set drop-column drop-index drop-table
filter from full-join
group-by having insert-into
join-by join lateral left-join limit offset on-conflict
on-duplicate-key-update
order-by over partition-by refresh-materialized-view
rename-column rename-table returning right-join
select select-distinct select-top select-distinct-top
values where window with with-columns
with-data within-group]]))
(deftest select-into-tests
(testing "SELECT INTO"
(is (= ["SELECT * INTO foo FROM bar"]
(sql/format {:select :* :into :foo :from :bar})))
(is (= ["SELECT * INTO foo IN otherdb FROM bar"]
(sql/format {:select :* :into [:foo :otherdb] :from :bar})))
(is (= ["SELECT * INTO foo FROM bar"]
(sql/format (-> (select '*) (h/into 'foo) (from 'bar)))))
(is (= ["SELECT * INTO foo IN otherdb FROM bar"]
(sql/format (-> (select :*) (h/into :foo :otherdb) (from :bar))))))
(testing "SELECT BULK COLLECT INTO"
(is (= ["SELECT * BULK COLLECT INTO foo FROM bar"]
(sql/format {:select :* :bulk-collect-into :foo :from :bar})))
(is (= ["SELECT * BULK COLLECT INTO foo LIMIT ? FROM bar" 100]
(sql/format {:select :* :bulk-collect-into [:foo 100] :from :bar})))
(is (= ["SELECT * BULK COLLECT INTO foo FROM bar"]
(sql/format (-> (select :*) (bulk-collect-into :foo) (from :bar)))))
(is (= ["SELECT * BULK COLLECT INTO foo LIMIT ? FROM bar" 100]
(sql/format (-> (select :*) (bulk-collect-into :foo 100) (from :bar)))))))