Fork me on GitHub
#honeysql
<
2023-12-14
>
isak18:12:43

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

p-himik18:12:53

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

isak18:12:15

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

isak18:12:35

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

seancorfield18:12:38

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

seancorfield18:12:06

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

seancorfield18:12:58

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

isak18:12:14

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.

seancorfield18:12:55

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

👌 1
p-himik19:12:42

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