#511 add tests; document bigquery create or replace

This commit is contained in:
Sean Corfield 2023-10-21 14:51:13 -07:00
parent 7d56daacca
commit caca08fd5b
3 changed files with 24 additions and 5 deletions

View file

@ -1,7 +1,7 @@
# Changes # Changes
* 2.4.next in progress * 2.4.next in progress
* Support BigQuery `CREATE OR REPLACE` (work-in-progress). * Address [#511](https://github.com/seancorfield/honeysql/issues/511) by adding support for BigQuery `CREATE OR REPLACE`.
* Address [#510](https://github.com/seancorfield/honeysql/issues/510) by adding some NRQL support (work-in-progress). * Address [#510](https://github.com/seancorfield/honeysql/issues/510) by adding some NRQL support (work-in-progress).
* Fix [#509](https://github.com/seancorfield/honeysql/issues/509) by checking for `ident?` before checking keyword/symbol. * Fix [#509](https://github.com/seancorfield/honeysql/issues/509) by checking for `ident?` before checking keyword/symbol.

View file

@ -229,7 +229,8 @@ CREATE TABLE quux
`:create-table-as` can accept a single table name or a sequence `:create-table-as` can accept a single table name or a sequence
that starts with a table name, optionally followed by that starts with a table name, optionally followed by
a flag indicating the creation should be conditional a flag indicating the creation should be conditional
(`:if-not-exists` or the symbol `if-not-exists`), (`:if-not-exists` or the symbol `if-not-exists` or,
for BigQuery `:or-replace` or the symbol `or-replace`),
optionally followed by a `{:columns ..}` clause to specify optionally followed by a `{:columns ..}` clause to specify
the columns to use in the created table, optionally followed the columns to use in the created table, optionally followed
by special syntax to specify `TABLESPACE` etc. by special syntax to specify `TABLESPACE` etc.
@ -261,7 +262,7 @@ A more concise version of the above can use the `TABLE` clause:
```clojure ```clojure
user=> (sql/format {:create-table-as [:metro :if-not-exists user=> (sql/format {:create-table-as [:metro :or-replace
{:columns [:foo :bar :baz]} {:columns [:foo :bar :baz]}
[:tablespace [:entity :quux]]], [:tablespace [:entity :quux]]],
:table :cities, :table :cities,
@ -269,7 +270,7 @@ user=> (sql/format {:create-table-as [:metro :if-not-exists
:with-data false} :with-data false}
{:pretty true}) {:pretty true})
[" ["
CREATE TABLE IF NOT EXISTS metro (foo, bar, baz) TABLESPACE quux AS CREATE OR REPLACE TABLE metro (foo, bar, baz) TABLESPACE quux AS
TABLE cities TABLE cities
WHERE metroflag = ? WHERE metroflag = ?
WITH NO DATA WITH NO DATA
@ -284,7 +285,13 @@ will be turned into SQL keywords (this is true for all of the
{:create-table-as [:temp :metro :if-not-exists [..]] ..} {:create-table-as [:temp :metro :if-not-exists [..]] ..}
``` ```
to produce `CREATE TEMP TABLE IF NOT EXISTS metro ..`. to produce `CREATE TEMP TABLE IF NOT EXISTS metro ..`, or:
```
{:create-table-as [:temp :metro :or-replace [..]] ..}
```
to produce `CREATE OR REPLACE TEMP TABLE metro ..`.
## create-extension ## create-extension

View file

@ -559,6 +559,18 @@
(where [:= :metroflag "y"]) (where [:= :metroflag "y"])
(with-data false))) (with-data false)))
["CREATE OR REPLACE TABLE metro AS SELECT * FROM cities WHERE metroflag = ? WITH NO DATA" "y"])) ["CREATE OR REPLACE TABLE metro AS SELECT * FROM cities WHERE metroflag = ? WITH NO DATA" "y"]))
(is (= (sql/format (-> (create-table-as :temp :metro :if-not-exists)
(select :*)
(from :cities)
(where [:= :metroflag "y"])
(with-data false)))
["CREATE TEMP TABLE IF NOT EXISTS metro AS SELECT * FROM cities WHERE metroflag = ? WITH NO DATA" "y"]))
(is (= (sql/format (-> (create-table-as :temp :metro :or-replace)
(select :*)
(from :cities)
(where [:= :metroflag "y"])
(with-data false)))
["CREATE OR REPLACE TEMP TABLE metro AS SELECT * FROM cities WHERE metroflag = ? WITH NO DATA" "y"]))
(is (= (sql/format (-> (create-materialized-view :metro :if-not-exists) (is (= (sql/format (-> (create-materialized-view :metro :if-not-exists)
(select :*) (select :*)
(from :cities) (from :cities)