我正在尝试让Hasql对“select ... where in”查询中的列表进行编码。如果我使用contravariant-extras中的contramany
,则会出现问题,但我在运行时遇到语法错误。
import qualified Database.Encoders as E
import Contravariant.Extras
getTeamMembership :: Query [TeamId] [(TeamId, EmployeeId)]
getTeamMembership = statement q enc def True
where
enc = contramany (E.value E.teamId)
q = "select workteam, employee \
\from workteam_employee where workteam in $1"
是否无法对参数列表进行编码?
答案 0 :(得分:2)
“IN”运算符不支持。您只能使用它指定各个值(例如IN ($1, $2, $3)
)。但是,根据the docs,使用阵列编码器和any
以及all
Postgres函数可以轻松实现所需。
有some Hasql tests showing it in action。
问题跟踪器上也有a discussion on that subject。