lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
9.01k stars 910 forks source link

error when insert: sql: converting argument $17 type: unsupported type []string, a slice of string #945

Open elvis-hp opened 4 years ago

elvis-hp commented 4 years ago

Hi there! I have a model in golang: type Transaction struct { ID stringdb:"id", Status intdb:"status", Users []stringdb:"users", and this is the sql for insert: sqlStr := INSERT INTO transactions (data, users) VALUES (:data, :users) RETURNING id tx := st.DB.MustBegin() defer tx.Commit() _, err := tx.NamedQuery(sqlStr, txs) return err But I got an err: sql: converting argument $17 type: unsupported type []string, a slice of string Can someone help to fix that, thank you very much!

tanqhnguyen commented 4 years ago

How about https://godoc.org/github.com/lib/pq#Array ?

Alternatively, you can/should also change the Users type from []string to pq.StringArray so that pq knows how to parse it

abdoroot commented 4 months ago

@tanqhnguyen thanks its work for me