In SQLx, there arises a need to query a table with values stored in a slice. This can be achieved by utilizing the In() helper function.
To address the given error, the following code snippet can be employed:
var qids []int // Populate qids dynamically query, args, err := sqlx.In("SELECT * FROM quote WHERE qid IN (?)", qids) if err != nil { log.Fatal(err) } database.SQL := sqlx.MustConnect("driver_name", "dsn") query = database.SQL.Rebind(query) // Assuming database.SQL is a *sqlx.DB err = database.SQL.Select("es, query, args...) if err != nil { log.Fatal(err) }
For further reference, the following documentation is recommended:
The above is the detailed content of How to Use SQLx\'s `In()` Function to Query MySQL with a Slice of IDs?. For more information, please follow other related articles on the PHP Chinese website!