honeysql

isak 2023-12-14T18:16:43.253389Z

Does honeysql support this syntax? ["col = ANY(?)" (int-array data)]

p-himik 2023-12-14T18:21:53.330749Z

[:= :col [:any (int-array data)]].

isak 2023-12-14T18:25:26.080969Z

Nice, thanks @p-himik

isak 2023-12-14T18:38:15.301219Z

Is there a way to add ::integer[] ?

isak 2023-12-14T18:38:35.936919Z

E.g.,: ["col = ANY(?::integer[])" (int-array data)]

seancorfield 2023-12-14T18:40:24.740319Z

:cast

seancorfield 2023-12-14T18:43:38.356979Z

The array type is a bit tricky since [] are not legal in keywords but you could do:

user=> (sql/format [:cast [:any (into-array (range 4))] [:raw "integer[]"]])
["CAST(ANY(?) AS integer[])" #object["[Ljava.lang.Long;" 0x2e1ddc90 "[Ljava.lang.Long;@2e1ddc90"]]

seancorfield 2023-12-14T18:44:06.068159Z

Hmm, no, you'll want cast inside any... just a sec...

seancorfield 2023-12-14T18:44:58.974009Z

Something like this...

user=> (sql/format [:= :col [:any [:cast (into-array (range 4)) [:raw "integer[]"]]]])
["col = ANY(CAST(? AS integer[]))" #object["[Ljava.lang.Long;" 0x63d4f0a2 "[Ljava.lang.Long;@63d4f0a2"]]

isak 2023-12-14T18:46:14.541619Z

Ok right, I see. Thank you. I'm new to postgres so I wasn't sure yet if CAST was the exact same, but I guess it is.

seancorfield 2023-12-14T18:47:55.520789Z

CAST( x AS y ) is the portable SQL version. x::y is not as widely supported AFAIK.

👌 1
p-himik 2023-12-14T19:33:42.818089Z

There's a separate syntax for when you need array[1, 2, 3]::integer[] - [:array [1 2 3] :integer]. Doesn't seem applicable here though. And I'm not sure whether it could be extended or not to support Java array values.

👍 1