我正在尝试获取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"
是否无法对参数列表进行编码?
最佳答案
“IN”运算符不支持这一点。您只能用它指定单个值(例如,IN ($1, $2, $3)
)。然而,您想要的东西可以通过数组编码器以及 any
和 all
Postgres 函数轻松实现,如 the docs 所示。 .
有some Hasql tests showing it in action .
还有a discussion on that subject在问题跟踪器上。
关于postgresql - 对 Hasql 查询的参数列表进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42138062/