我正在尝试使用Database.HDBC.PostgreSQL执行类似的操作:
run c "update questions set deleted = now() where question_id in (?)" [toSql ids]
其中id是[Int]。但我收到了错误
No instance for (Data.Convertible.Base.Convertible [Int] SqlValue)
如何填写HDBC的IN占位符?
答案 0 :(得分:2)
我认为你不能避免动态构建查询,但你仍然可以避免SQL注入等。
import Control.Applicative ((<$), (<$>))
import Data.List (intersperse)
let query = "update questions set deleted = now() where question_id in ("
++ intersperse ',' ('?' <$ ids)
++ ")"
in run c query (toSql <$> ids)
指向intersperse
,<$>
,<$
的文档的链接。