Fork me on GitHub
#honeysql
<
2021-05-18
>
borkdude12:05:20

@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[])

borkdude12:05:05

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

borkdude12:05:11

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

borkdude12:05:43

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

seancorfield15:05:20

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:

borkdude17:05:45

@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

seancorfield17:05:05

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

borkdude20:05:30

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