Fork me on GitHub
#hugsql
<
2024-01-31
>
Sam18:01:03

How do I translate this to hugsql, where the ids are a parameter?

WITH inputids (id)
AS (VALUES (109734), (109733), (1111111))
SELECT ib.*
FROM inputids ib
LEFT JOIN foo f
ON ib.id = f.id
WHERE f.id IS NULL
So something like
WITH inputids (id)
AS (VALUES :v*:ids)
SELECT ib.*
FROM inputids ib
LEFT JOIN foo f
ON ib.id = f.id
WHERE f.id IS NULL
But working

Sam21:01:50

I did it using :raw and

(defn sqlvals [vals]
  (string/join "," (map #(format "('%s')" %) vals)))
Not the prettiest but it works!

Sam22:01:08

This:

WITH inputids (id)
AS (VALUES :t*:ids)
SELECT ib.*
FROM inputids ib
LEFT JOIN foo f
ON ib.id = f.id
WHERE f.id IS NULL
gives the error count not supported on this type: Long

curtis.summers22:01:16

:ids need to take the expected shape of [[3][2][1]], since this is a list of tuples.

Sam08:02:09

Oh... That was easy. Thank you!