UNIQUE on the table
Opened this issue · 4 comments
I would like to achieve the following (from here:
CREATE TABLE example (
a integer,
b integer,
c integer,
UNIQUE (a, c)
);
And I see that there is an (sql/call :unique ...)
I can use, but the problem is that I don't really see how to achieve that, maybe because I don't know how to hook in that :with-columns
map.
Any recommendation on how to do that?
This is the ugly workaround:
(let [unique-sql & _] (when unique-columns
(-> (apply sql/call :unique unique-columns)
(sql/format :parameterizer :postgresql)))
(str/replace table-stmt #"\)$" (str ", " unique-sql ")"))
@krish8664 any advice/recommendation on this one?
@arichiardi I think the idea would be to come up with a way to specify constraints outside of the inlined way it is possible right now. Let me think about this for a bit.
Ideally I would like something of the following syntax
(-> (create-table :films)
(with-columns [[:a :integer]
[:b :integer]
[:c :integer])
(constrain [:unique [:a :c]]))
This should be possible to achieve. Alternatively if you have found a better way to do this, I would like to hear about that.
P.S: Sorry about the extremely delayed response, I haven't been very active here on github for quite sometime. This would change going forward.
Agree that what you wrote feels right, basically a way to add constraints to columns.
I see inline would be difficult to make it work.
PS.: Good to have you back!