1

I'm trying to use NULL to reuse queries for both specific searches as well as returning index (basically implementing the idea discussed here http://dev.solita.fi/2015/12/29/SQL-in-applications.html). However, I'm getting ERROR: could not determine data type of parameter $1 anytime I try to use the function body with the [] params.

Here's the clojure

(defn get-ips
  "Get a list of IPs and their User Ids"
  ([] (ip-addresses {:uids nil}))
  ([uids] (ip-addresses {:uids uids})))

Here's the sql

-- name: ip-addresses
SELECT ipo.ip_address_id::varchar as address, ipo.user_id
FROM ip_ownerships AS ipo
WHERE :uids IS NULL OR ipo.user_id IN (:uids)
BWStearns
  • 2,567
  • 2
  • 19
  • 33

1 Answers1

1

So I just found the answer. The solution is to manually cast the parameter's type:

-- name: ip-addresses
SELECT ipo.ip_address_id::varchar as address, ipo.user_id
FROM ip_ownerships AS ipo
WHERE :uids::int IS NULL OR ipo.user_id IN (:uids)
BWStearns
  • 2,567
  • 2
  • 19
  • 33