diff --git a/src/dsql/pg.clj b/src/dsql/pg.clj index 9a3db53..8b762cd 100644 --- a/src/dsql/pg.clj +++ b/src/dsql/pg.clj @@ -1158,13 +1158,15 @@ (conj "TABLE") (cond-> not-ex (conj "IF NOT EXISTS")) (identifier opts table-name) + + (cond-> partition-of (conj "partition of" (name partition-of) )) + (cond-> (or columns constraint) (conj "(")) (cond-> columns (conj (mk-columns opts columns))) (cond-> (and columns constraint) (conj ",")) (cond-> constraint (conj (mk-table-constraint constraint))) (cond-> (or columns constraint) (conj ")")) - (cond-> partition-of (conj "partition of" (name partition-of) )) (cond-> for (conj "for values" (when-let [f (:from for)] (str "from (" f ")")) (when-let [t (:to for)] (str "to (" t ")")))) diff --git a/test/dsql/pg_test.clj b/test/dsql/pg_test.clj index 1d023c9..c27c55f 100644 --- a/test/dsql/pg_test.clj +++ b/test/dsql/pg_test.clj @@ -618,6 +618,20 @@ :columns {:a {:type "integer" }}} ["CREATE TABLE \"MyTable\" ( \"a\" integer )"]) + + (format= + {:ql/type :pg/create-table + :table-name "patient_000" + :if-not-exists true + :constraint {:primary-key [:id :partition]} + :partition-of "patient" + :partition-by {:method :range + :expr :partition} + :for {:from 0 :to 1001}} + ["CREATE TABLE IF NOT EXISTS patient_000 partition of patient ( PRIMARY KEY (\"id\", \"partition\") ) for values from (0) to (1001) partition by range ( partition )"] + ) + + (format= {:ql/type :pg/create-table :table-name "mytable"