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.
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...)