Fork me on GitHub
#honeysql
<
2022-06-23
>
markbastian20:06:56

What’s the best way to cast a select result to a string in honeysql? Say, my raw SQL is SELECT ID FROM TABLE; where ID is a UUID. I want to cast that to a string or varchar type.

sheluchin21:06:56

Probably depends on your database. HoneySQL just creates queries out of Clojure data structures. For Postgres:

(hh/select [[[:cast :did :text]] :did-as-txt])

markbastian21:06:13

Cool, thanks! I also did a little experimentation and discovered:

[(hsql/raw "row.id::text") :row_id]

👍 1
seancorfield23:06:10

That looks like HoneySQL v1? For anyone else reading this thread, in HoneySQL v2, :raw is a "function" now, [:raw "row.id::text"]

markbastian13:06:19

Yeah, that’s v1. Good callout. Thanks!