Skip to content

Commit

Permalink
Fix partition and columns order
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitem committed Dec 14, 2023
1 parent 1454fc6 commit fcb374e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/dsql/pg.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")"))))
Expand Down
14 changes: 14 additions & 0 deletions test/dsql/pg_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fcb374e

Please sign in to comment.