honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
2021-03-15T19:17:41.134100Z

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?

seancorfield 2021-03-15T19:39:47.134600Z

I don’t think that, as written, has ever been valid with strings.

seancorfield 2021-03-15T19:40:29.135400Z

(with [:A ["some sql thing" its params]] [:B ["another sql thing" more params]]) is more like it.

seancorfield 2021-03-15T19:42:12.136Z

Can you share exactly what you had with v1 that worked (that no longer works the same in v2)?

seancorfield 2021-03-15T19:43:25.136400Z

The syntax should not have changed between v1 and v2 as far as I’m aware @dcj

seancorfield 2021-03-15T19:46:36.138Z

The difference there is that modifiers no longer exists in v2 (`:select-distinct` replaces :select and :modifiers as separate things).

2021-03-15T20:10:30.139300Z

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

seancorfield 2021-03-15T20:12:53.140500Z

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.

bartuka 2021-03-15T20:30:31.141500Z

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.

seancorfield 2021-03-15T21:28:50.141700Z

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"]

👍 1
seancorfield 2021-03-15T21:29:42.142300Z

Not sure about the (num,letter) piece at the end… I don’t even understand that SQL syntax…

2021-03-15T23:26:34.144Z

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?

2021-03-15T23:37:22.144800Z

Apparently yes!

seancorfield 2021-03-15T23:41:53.146600Z

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.