Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
elvis-hp opened this issue Mar 2, 2020 · 1 comment

Comments

@elvis-hp
Copy link

elvis-hp commented Mar 2, 2020

Hi there!
I have a model in golang:
type Transaction struct { ID string db:"id", Status int db:"status", Users []string db:"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
Copy link

tanqhnguyen commented Mar 10, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants