This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-15
Channels
- # announcements (8)
- # asami (10)
- # babashka (16)
- # beginners (86)
- # calva (22)
- # chlorine-clover (9)
- # circleci (20)
- # clj-kondo (13)
- # cljs-dev (20)
- # cljsrn (3)
- # clojure (144)
- # clojure-australia (10)
- # clojure-europe (126)
- # clojure-italy (5)
- # clojure-nl (8)
- # clojure-norway (4)
- # clojure-serbia (9)
- # clojure-uk (7)
- # clojurescript (14)
- # cursive (20)
- # data-science (1)
- # datomic (20)
- # figwheel-main (5)
- # fulcro (23)
- # graalvm (7)
- # graphql (25)
- # honeysql (15)
- # hugsql (3)
- # jobs (2)
- # lambdaisland (2)
- # leiningen (4)
- # lsp (102)
- # malli (3)
- # off-topic (51)
- # overtone (5)
- # pathom (27)
- # portal (11)
- # quil (1)
- # re-frame (19)
- # reagent (31)
- # remote-jobs (1)
- # reveal (3)
- # rewrite-clj (56)
- # shadow-cljs (45)
- # startup-in-a-month (1)
- # tools-deps (9)
I am attempting to migrate to honeysql 2 from 1.
Many things are working, but I'm having trouble with one very complex CTE:
The docs for with
state:
The argument to :with (or :with-recursive) is a sequences of pairs, each of a result set name (or description) and a basic SQL statement
I'm having trouble parsing this, and the examples given use a different style than I am used to....
Previously I did something like:
(with [:A "some sql thing"]
[:B "another sql thing"]
...)
Is that still valid?I don’t think that, as written, has ever been valid with strings.
(with [:A ["some sql thing" its params]] [:B ["another sql thing" more params]])
is more like it.
Can you share exactly what you had with v1 that worked (that no longer works the same in v2)?
The syntax should not have changed between v1 and v2 as far as I’m aware @dcj
There are two CTEs in the V1 tests: https://github.com/seancorfield/honeysql/blob/develop/test/honeysql/core_test.cljc#L16-L62 and here’s the same tests for v2 https://github.com/seancorfield/honeysql/blob/v2/test/honey/sql/helpers_test.cljc#L22-L62
The difference there is that modifiers
no longer exists in v2 (`:select-distinct` replaces :select
and :modifiers
as separate things).
Sorry, I over simplified my example with
and confused things. I don't use strings, your re-write is basically indeed what I did both before and now
Sounds like you’ll need to share more of what code you actually have then and compare the V1 and V2 data structures produced and what the formatter does with each. That’s why V2 has different namespaces so you can try them side-by-side.
hi!! is it possible to perform select from values in honeysql? => SELECT * FROM (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (num,letter);
? I am still getting the hang of it.
In V2:
user=> (-> (select :*) (from [(values [[1, "one"] [2, "two"] [3, "three"]]) :t]) (sql/format))
["SELECT * FROM (VALUES (?, ?), (?, ?), (?, ?)) AS t" 1 "one" 2 "two" 3 "three"]
Not sure about the (num,letter)
piece at the end… I don’t even understand that SQL syntax…
Here is the raw SQL string I am attempting to model in honey2:
(SELECT fid, pca_raw, dca, X.path[1] AS id, X.geom AS g, ST_M(geom) AS m FROM flts_close CROSS JOIN ST_DumpPoints(t_trajectory) AS X)
So:
(println (sql/format (-> (select :fid :pca_raw :dca [[:raw "X.path[1]"] :id] [:X.geom :g] [[:ST_M :geom] :m])
(from :flts_close)
(sql.helpers/cross-join [[:ST_DumpPoints :t_trajectory] :X]))))
[SELECT fid, pca_raw, dca, X.path[1] AS id, X.geom AS g, ST_M(geom) AS m FROM flts_close CROSS JOIN ST_DUMPPOINTS(t_trajectory) X]
Is the part after the CROSS JOIN the same as AS X
above?In cross join x as y
, the x as y
part is just an aliased pair (like other joins). I’ll have a think about that array indexing syntax but I don’t realistically think there’s anything I can do that would make it easier/neater in HoneySQL than wrapping [:raw ..]
around the expressions.