I'm trying to write a query that takes a list parameter (ie, a single parameter which is a list of values). It appears that this is at least sometimes possible in PostgreSQL (https://stackoverflow.com/a/10829760/836390). What I want is something like this:
rows, err := db.Query("SELECT * FROM table WHERE id in $1", []int{1, 2, 3})
However, when I execute this using the pq driver, I get an error:
sql: converting Exec argument #0's type: unsupported type []int, a slice
Is this simply not supported in pq
yet, or is this not supported in database/sql
, or not in PostgreSQL at all, or what?
You can use pq.Array with slice parameters nowadays. So the query would look like:
rows, err := db.Query("SELECT * FROM table WHERE id in $1", pq.Array([]int{1, 2, 3}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With