This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-29
Channels
- # announcements (6)
- # beginners (110)
- # calva (18)
- # clj-kondo (19)
- # cljs-dev (27)
- # clojars (10)
- # clojure (38)
- # clojure-art (2)
- # clojure-europe (13)
- # clojure-germany (1)
- # clojure-norway (26)
- # clojure-uk (2)
- # clojurescript (10)
- # conjure (9)
- # cursive (12)
- # data-science (3)
- # datomic (22)
- # emacs (8)
- # helix (9)
- # honeysql (18)
- # introduce-yourself (1)
- # jobs (1)
- # leiningen (8)
- # lsp (22)
- # missionary (9)
- # nbb (11)
- # off-topic (83)
- # pathom (5)
- # pedestal (4)
- # polylith (1)
- # portal (1)
- # re-frame (3)
- # reitit (15)
- # remote-jobs (1)
- # rum (4)
- # shadow-cljs (88)
- # specter (12)
- # testing (1)
- # vim (39)
I’m trying to generate SQL to create an index in postgresql, but it seems that the (add-index) fn only works for :primary-key and :unique, has anyone faced this problem? In postgresql docs, I can only find the CREATE INDEX
clause to create new indexes on certain column(s), but not the alter table … add index ….
as generated by honeysql
https://github.com/seancorfield/honeysql/issues/348 -- TL;DR: it's hard to support generically because it's almost entirely database-specific.
You should be able to add a general index (without primary or unique) -- see https://cljdoc.org/d/com.github.seancorfield/honeysql/2.2.891/doc/getting-started/sql-clause-reference#add-index-drop-index @U6CN6JQ22
I tried to execute the SQL generated directly on postgres, but it seems that syntax is not supported:
type "look" does not exist
What exact SQL are you trying to run there?
ALTER TABLE fruit ADD INDEX look(appearance)
^ This one, having a table fruit with appearance columnSo it's expecting a type of index where you currently look
. Let me look at the PG docs...
Try adding {:quoted true}
to the format
call. All the examples I can find of alter table .. add index ..
for PG seem to use quoted names.
DDL is a giant mess and varies dramatically from database to database which is why HoneySQL hadn't used to support any DDL. I'm gradually adding the more common pieces but some of them are just really hard to add in any way that works across multiple databases.
Adding :quoted true didn’t work, it still complains. Even executing the SQL with quotes doesn’t work
ALTER TABLE fruit ADD INDEX 'look'('appearance')
(now a syntax error)
I imagine it’s a mess and by the issue you posted looks like create index might not be that general, for now I will create and register the clause myself
thanks for the help 🙂It should be double quotes, not single.
ALTER TABLE "fruit" ADD INDEX "look" ("appearance")
That syntax is used in several tutorials I found for PostgreSQL so I assumed it works -- I don't use PG myself.
I also don't currently have DDL tests for this so I should add those.
OK. Thanks for testing that. The tutorials must be wrong (no surprise, I guess).