YesQL / pgsql“无法确定参数$ 1的数据类型”

时间:2018-06-19 18:38:11

标签: postgresql clojure hugsql

我正在尝试使用NULL重用针对特定搜索和返回索引的查询(基本上实现了此处http://dev.solita.fi/2015/12/29/SQL-in-applications.html所讨论的思想)。但是,每当我尝试将函数主体与ERROR: could not determine data type of parameter $1参数一起使用时,都会得到[]

这是clojure

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

这是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)

1 个答案:

答案 0 :(得分:1)

所以我才找到答案。解决方案是手动转换参数的类型:

-- 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)