This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-05
Channels
- # aleph (90)
- # announcements (4)
- # aws (2)
- # beginners (61)
- # calva (2)
- # cljs-dev (8)
- # cljsrn (12)
- # clojars (4)
- # clojure (42)
- # clojure-europe (1)
- # clojure-finland (1)
- # clojure-greece (2)
- # clojure-houston (1)
- # clojure-italy (3)
- # clojure-nl (30)
- # clojure-spec (41)
- # clojure-uk (87)
- # clojurescript (44)
- # cursive (12)
- # data-science (11)
- # datomic (24)
- # defnpodcast (1)
- # fulcro (18)
- # hyperfiddle (1)
- # jobs (2)
- # juxt (11)
- # kaocha (3)
- # london-clojurians (5)
- # mount (2)
- # nrepl (2)
- # off-topic (9)
- # onyx (25)
- # other-languages (1)
- # parinfer (3)
- # pathom (5)
- # pedestal (3)
- # portkey (1)
- # re-frame (21)
- # reagent (24)
- # remote-jobs (7)
- # schema (2)
- # shadow-cljs (59)
- # spacemacs (5)
- # specter (7)
- # sql (9)
- # tools-deps (13)
Why does this result in an error:
(require '[honeysql.core :as sql])
(jdbc/query
db-spec-user
(sql/format
{:select [:*]
:from ["fruit"]}))
Execution error (PSQLException) at org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse (QueryExecutorImpl.java:2440).
ERROR: syntax error at or near "$1"
Position: 15
And this doesn't:
(jdbc/query
db-spec-user
(sql/format
{:select [:*]
:from [:fruit]}))
I assume it's because passing in a string implies a different meaning sometimes. Shouldn't passing a string in the context of the :from
work though?It's really the difference between (jdbc/query db-spec ["SELECT * FROM ?" "fruit"])
and (jdbc/query db-spec ["SELECT * FROM fruit"])
.
honeysql transforms the datastructure you give it in to the standard query + params vector that clojure.java.jdbc uses
HoneySQL assumes keywords correspond to literal SQL names (tables, columns) but strings are "values" that should be parameterized.
Oh, ok. I assume the design decision was that that definition applies to all parts of the query, even though it doesn't make sense for particular parts of the query.
Yes, rather than have special rules for different parts of the data structure, it's a lot simpler to have consistent rules -- since users can extend the DSL.