3

I am using postgresql go client: github.com/jackc/pgx I would like to execute SQL query looking a bit like this one:

ids := []int{2,3,4}
rows, err = pool.Query("SELECT id, title FROM document WHERE id IN ($1)", ids)

The result is a following error: cannot convert [2 3 4] to Int8

Can I achieve such effect without concatenating string like id=$1 OR id=$2 OR.... ?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Lemurata
  • 235
  • 2
  • 12
  • 1
    Postgres doesn't let you use a single identifier for a list. It doesn't understand slices. I've not use pgx, but I know sqlx specifically has a `In()` function to remap a slice to a list of args. You can manually do this yourself, though, by replacing that `$1` with an iterative list of placeholders, akin to this: https://play.golang.org/p/C53TX6_KXP1 – Kaedys Mar 02 '18 at 16:54

0 Answers0