This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-26
Channels
- # announcements (17)
- # babashka (68)
- # beginners (8)
- # biff (14)
- # calva (25)
- # cherry (10)
- # clj-kondo (1)
- # clj-on-windows (12)
- # cljsrn (6)
- # clojure (134)
- # clojure-berlin (1)
- # clojure-europe (33)
- # clojure-nl (4)
- # clojure-norway (6)
- # clojure-uk (10)
- # clojurescript (9)
- # datalevin (8)
- # datomic (34)
- # docker (1)
- # emacs (31)
- # fulcro (6)
- # honeysql (8)
- # java (7)
- # joyride (14)
- # kaocha (7)
- # malli (11)
- # nbb (4)
- # off-topic (11)
- # pedestal (14)
- # rdf (53)
- # re-frame (6)
- # reagent (39)
- # reitit (2)
- # releases (9)
- # rewrite-clj (14)
- # shadow-cljs (97)
- # specter (1)
- # testing (5)
- # tools-deps (12)
- # vim (4)
- # xtdb (9)
How can I create honeysql equivalent for:
CREATE TABLE IF NOT EXISTS "Blog" (
"id" SERIAL NOT NULL,
"title" TEXT NOT NULL,
"comments" TEXT[] DEFAULT ARRAY['hello', 'world']::TEXT[],
CONSTRAINT "blog_pkey" PRIMARY KEY ("id")
);
I am using following:
{:create-table [:blog :if-not-exists],
:with-columns
[[:id :uuid [:not nil]]
[:comments
[:raw "text[]"]
[:default [:raw "ARRAY[hello, world]::text[]"]]]
[[:constraint :blog_pkey] [:primary-key :id]]]}
But this results in
["CREATE TABLE IF NOT EXISTS blog (id UUID NOT NULL, comments TEXT[] DEFAULT ARRAY[HELLO, WORLD]::TEXT[], CONSTRAINT blog_pkey PRIMARY KEY(ID))"]
Cases in the default values are incorrect.
Is there a way I can do it without using :raw
operator.There's a GH issue open that mentions this https://github.com/seancorfield/honeysql/issues/386 -- DDL support is very tricky to get right since it is so vendor-specific and the heuristic for upper-casing parts of the declaration is too zealous at the moment. So the TL;DR: is "No, you can't do this right now" but I plan to fix it at some point.
Got it. Thanks. Are there ideas about how you are planning to solve it? I can try to implement it for my use case.
I don't know yet. DDL is horribly inconsistent and doesn't follow the "normal" rules of SQL syntax.
There are good reasons why HoneySQL v1 pretty much didn't touch DDL at all 🙂
Hey @U02JRAM6CBA I ended up with custom clause like this one
This is great. WIll give adding custom-clause a try.