From d24ee428f38fc519b71f657a5ac2312f2b47abc0 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Tue, 23 Jul 2024 22:22:25 -0700 Subject: [PATCH] fixes #536 Signed-off-by: Sean Corfield --- CHANGELOG.md | 1 + doc/postgresql.md | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70da4d5..817793d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 2.6.next in progress + * Address [#536](https://github.com/seancorfield/honeysql/issues/536) by noting what will not work with PostgreSQL (but works with other databases). * Address [#533](https://github.com/seancorfield/honeysql/issues/533) by adding `honey.sql/*escape-?*` which can be bound to `false` to prevent `?` being escaped to `??` when used as an operator or function. * Address [#526](https://github.com/seancorfield/honeysql/issues/526) by using `format-var` in DDL, instead of `format-entity`. * Update JDK test matrix (adopt -> temurin, 19 -> 21). diff --git a/doc/postgresql.md b/doc/postgresql.md index 73b5e8d..768d8a8 100644 --- a/doc/postgresql.md +++ b/doc/postgresql.md @@ -456,11 +456,6 @@ user=> (-> (alter-table :fruit) (drop-column :skin) sql/format) ["ALTER TABLE fruit DROP COLUMN skin"] -;; alter table alter column: -user=> (-> (alter-table :fruit) - (alter-column :name [:varchar 64] [:not nil]) - sql/format) -["ALTER TABLE fruit ALTER COLUMN name VARCHAR(64) NOT NULL"] ;; alter table rename column: user=> (-> (alter-table :fruit) (rename-column :cost :price) @@ -473,6 +468,29 @@ user=> (-> (alter-table :fruit) ["ALTER TABLE fruit RENAME TO vegetable"] ``` +The following does not work for PostgreSQL, but does work for several other databases: + +```clojure +;; alter table alter column: +user=> (-> (alter-table :fruit) + (alter-column :name [:varchar 64] [:not nil]) + sql/format) +["ALTER TABLE fruit ALTER COLUMN name VARCHAR(64) NOT NULL"] +``` + +For PostgreSQL, you need separate statements: + +```clojure +user=> (-> (alter-table :fruit) + (alter-column :name :type [:varchar 64]) + sql/format) +["ALTER TABLE fruit ALTER COLUMN name TYPE VARCHAR(64)"] +user=> (-> (alter-table :fruit) + (alter-column :name :set [:not nil]) + sql/format) +["ALTER TABLE fruit ALTER COLUMN name SET NOT NULL"] +``` + The following PostgreSQL-specific DDL statements are supported (with the same syntax as the nilenso library but `sql/format` takes slightly different options):