douqinlu4217 2016-09-12 23:32
浏览 1707

PostgreSQL“?”参数占位符不适用于“ WITH”

I am trying to use ? in the following way (I use it in Golang to generate query, but it seems like it is not Go dependent):

WITH Tmp(name, enabled) AS (
    VALUES(?, ?),(?, ?)
) 
UPDATE table_groups 
    SET enabled = (SELECT enabled 
                   FROM Tmp 
                   WHERE table_groups.name=Tmp.name) 
WHERE table_groups.name IN (SELECT name FROM Tmp)

getting:

syntax error at or near ","

If I substitute ? in the above statement by concrete values, everything works fine. Is there a problem using ? with WITH and how would I get around it? Thanks.

  • 写回答

1条回答 默认 最新

  • duansen6750 2016-09-12 23:42
    关注

    Go doesn't support this at of the box.

    You can use jmoiron/sqlx if you want this functional

    example using sqlx (from docs):

    var levels = []int{4, 6, 7}
    query, args, err := sqlx.In("SELECT * FROM users WHERE level IN (?);", levels)
    
    // sqlx.In returns queries with the `?` bindvar, we can rebind it for our backend
    query = db.Rebind(query)
    rows, err := db.Query(query, args...)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?