문제

I'm trying to do something like this with Database.HDBC.PostgreSQL:

run c "update questions set deleted = now() where question_id in (?)" [toSql ids]

where ids is [Int]. But I get the error

No instance for (Data.Convertible.Base.Convertible [Int] SqlValue)

How do you fill in an IN placeholder with HDBC?

도움이 되었습니까?

해결책

I don't think you can avoid building the query dynamically, but you can still avoid SQL injection and the like.

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)

Links to documentation for intersperse, <$>, <$.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top