hugsql

Sam 2024-01-31T18:43:03.517519Z

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

Sam 2024-02-01T08:11:09.355529Z

Oh... That was easy. Thank you!

Sam 2024-01-31T21:36:50.577889Z

I did it using :raw and

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

curtis.summers 2024-01-31T22:01:09.576849Z

You can use a tuple list parameter type for this: https://www.hugsql.org/hugsql-in-detail/parameter-types/sql-tuple-list-parameters

Sam 2024-01-31T22:10:08.562819Z

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.summers 2024-01-31T22:18:16.287169Z

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