在Golang中传递整数以进行查询

时间:2018-11-01 09:49:59

标签: go

我在golang中的查询中传递字符串时遇到问题,这是我的尝试:

Exec(`UPDATE matches SET expected_completed_at= date + interval ? second WHERE match_id in (?);`,
duration, matchIDs)

持续时间类似于12544,查询读取为UPDATE matches SET expected_completed_at= date + interval '12544' second WHERE match_id in (?),我想不带单引号读取它吗?

1 个答案:

答案 0 :(得分:0)

查询中的显式强制转换应该起作用:

Exec(`
    UPDATE matches 
    SET 
        expected_completed_at = date + (interval $1::integer second)
    WHERE 
        match_id in ($2);
    `, duration, matchIDs)