Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create compound keys in table constraint with :unique #453

Closed
marrs opened this issue Jan 10, 2023 · 3 comments
Closed

Cannot create compound keys in table constraint with :unique #453

marrs opened this issue Jan 10, 2023 · 3 comments

Comments

@marrs
Copy link

marrs commented Jan 10, 2023

I'm trying to create a unique constraint on a table across multiple columns by doing something like the following

{:create-table [:foo]
 :with-columns [[:a :integer]
                [:b :integer]
                [[:constraint :foo_natural_key] [:raw "UNIQUE (a, b)"]]
]}

I'd like to write the query without having to invoke the :raw operator. I've tried [:unique :a :b], [:unique [:a :b]], and so on, but nothing seems to generate the correct code. Is there something I'm missing or is it a limitation of Honey?

@seancorfield
Copy link
Owner

seancorfield commented Jan 10, 2023

Does this help? #445

Otherwise I'll look at this when I get back from vacation (next week).

@seancorfield
Copy link
Owner

seancorfield commented Jan 14, 2023

I'm adding this example to the docs:

user=> (-> {:create-table [:bar]
            :with-columns
            [[:a :integer]
             [:b :integer]
             [[:constraint :foo_natural_key] :unique [:composite :a :b]]]}
           (sql/format))
["CREATE TABLE bar (a INTEGER, b INTEGER, CONSTRAINT foo_natural_key UNIQUE (a, b))"]

seancorfield added a commit that referenced this issue Jan 14, 2023
@marrs
Copy link
Author

marrs commented Jan 20, 2023

Sorry for the delay in replying. On the face of it, the docs look good. I'll let you know if I have any issues using them to adjust my schemas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants