Fork me on GitHub
#honeysql
<
2022-09-22
>
vonadz18:09:19

Am I missing something about how to use the ->> json operator for postgresql? I've tried to no avail in the select clause (select ...)

[:->> :report_summary :clicks]
and
[:->> :report_summary "clicks"]

seancorfield18:09:08

Did you require the honey.sql.pg-ops namespace?

seanc@Sean-win-11-laptop:~/oss/honeysql$ clj
Clojure 1.9.0
user=> (require '[honey.sql :as sql] '[honey.sql.helpers :refer :all] '[honey.sql.pg-ops :as pg] :reload)
...
nil
user=> (-> (select :*) (from :table) (where [:= :a [:->> :report_summary :clicks]]) (sql/format))
["SELECT * FROM table WHERE a = (report_summary ->> clicks)"]
user=>
See https://cljdoc.org/d/com.github.seancorfield/honeysql/2.3.928/doc/getting-started/postgresql-support#operators-with---and-

vonadz18:09:08

Yes. I'm getting "illegal syntax in select expression " Which goes away when I remove the line

seancorfield18:09:47

Show more of your code, please. As you can see above, it works.

vonadz18:09:49

Running gives me the same error for the select expression.

(require '[honey.sql :as sql] '[honey.sql.helpers :refer :all] '[honey.sql.pg-ops :as pg] :reload)

(-> {}
    (select
     [:->> :report_summary :clicks])
    (from :campaigns)
    (sql/format))

vonadz18:09:22

If I run it like you, in the where clause, it works

vonadz18:09:01

Seems like the issue is having it in select.

vonadz18:09:39

temporary work around is to just use raw

seancorfield18:09:19

Your syntax is wrong. Read the docs around SELECT and expressions to get the nesting correct.

seancorfield18:09:34

Sorry for shortness. Very busy right now.

seancorfield18:09:32

user=> (-> (select :col1 [:col2 :alias] [[:->> :report_summary :clicks]]) (from :table) (sql/format))
["SELECT col1, col2 AS alias, report_summary ->> clicks FROM table"]
user=>

vonadz18:09:45

Ah tits, thanks for catching that. Sorry for the false alarm

1
vonadz18:09:52

Small correction if anyone sees this in the future:

[[:->> :report_summary :clicks]]
should be
[[:->> :report_summary "clicks"]]