How to execute an IN lookup in SQL using Golang?

前端 未结 9 974
余生分开走
余生分开走 2020-12-01 02:12

What does Go want for the second param in this SQL query. I am trying to use the IN lookup in postgres.

stmt, err := db.Prepare(\"SELECT * FRO         


        
9条回答
  •  天涯浪人
    2020-12-01 02:23

    Rather pedestrian and only to be used if server generated. Where UserIDs is a slice (list) of strings:

    sqlc := `select count(*) from test.Logins where UserID 
                    in ("` + strings.Join(UserIDs,`","`) + `")`
    errc := db.QueryRow(sqlc).Scan(&Logins)
    

提交回复
热议问题