honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
borkdude 2021-05-18T12:12:20.000900Z

@seancorfield any idea about this one?

(sql/format {:select [:tzdb.source :tzdb.uri [:cast :tzdb.tag_uuids [:raw "text[]"]]]})
;;=>
["SELECT tzdb.source, tzdb.uri, cast AS tzdb.tag_uuids"]
I want something like cast(tzdb.tag_uuids as text[])

borkdude 2021-05-18T12:16:05.001100Z

This also doesn't work for me: (sql/format {:select [:tzdb.source :tzdb.uri [:raw "tzdb.tag_uuids::text[]"]]})

borkdude 2021-05-18T12:22:11.001500Z

Again, this works: (sql/format {:select ['foo 'bar (symbol "tzdb.tag_uuids::text[]")]}) but it's pretty ugly :)

borkdude 2021-05-18T12:23:43.002200Z

perhaps instead of (symbol "tzdb.tag_uuids::text[]") honeysql could support a raw function, since [:raw ...] doesn't seem to work everywhere.

seancorfield 2021-05-18T15:27:20.002300Z

For functions in a select you need an extra level of brackets - otherwise it's an aliased column. The docs explain that but could clearly do a better job:grin:

borkdude 2021-05-18T17:28:45.003Z

@seancorfield 🙏

:select [:tzdb.source :tzdb.uri [[:raw "tzdb.tag_uuids::text[]"]]]
there's nothing that can't be fixed using an extra pair of brackets

seancorfield 2021-05-18T17:55:05.003800Z

Well, :select [[:a :b]] means SELECT a AS b so :select [[[:foo :a] :b]] means SELECT FOO(a) AS b

borkdude 2021-05-18T20:11:30.004200Z

of course, once you see it you can't unsee it