I have a list of uuid strings that I want to use to filter a query. I can get the query to work if I loop over elements in my list like so:
for i, fileUID := range fileUIDs {
db.Exec("DELETE FROM files WHERE uid = $1::uuid", fileUID)
}
But I'd like to get it working using the list:
db.Exec("DELETE FROM files WHERE uid IN $1::uuid[]", fileUIDs)
Is this possible? I can't seem to get it working.
I tried the solution in How to execute an IN lookup in SQL using Golang? but I get errors like pq: syntax error at or near ","
when using plain ?
or pq: syntax error at or near "::"
when using ?:uuid
. I used the following:
fileUIDArgs := make([]interface{}, len(fileUIDs))
for i, fileUID := range fileUIDs {
fileUIDArgs[i] = interface{}(fileUID)
}
//also tried using "?::uuid"
myPsql := "DELETE FROM files WHERE uid IN (" + "?" + strings.Repeat(",?", len(uidStrings)-1) + ")"
db.Exec(myPsql, fileUIDArgs...)