G
G
Gravio2019-09-27 19:26:28
PostgreSQL
Gravio, 2019-09-27 19:26:28

GO array in WHERE id IN()?

There is a query db.Query("SELECT * FROM words WHERE id IN ($1);", list)
And also a list slice - []int{75929,77348}
The script gives an error: converting argument $1 type: unsupported type [] int, a slice of int
How to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Papa, 2019-09-27
@Gravio

db.Query("SELECT * FROM words WHERE id = ANY($1);", pq.Array(list))

D
Dmitry Shitskov, 2019-09-27
@Zarom

I recommend using an ORM like gorm. He definitely knows how to substitute arrays. Well, with plain queries, the chances of catching sql injection are high
. Otherwise, something like this
https://stackoverflow.com/a/38037586

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question