Answer the question
In order to leave comments, you need to log in
How to get parameters by name?
Hello, using the postgresql package, I usually get query result parameters like this: err := rows.Scan(&list.ID, &list.Name)
Now I'm interested in getting parameters by name, for example:
list.ID := rows.byName["id"]
list.Name := rows.byName["name"]
Answer the question
In order to leave comments, you need to log in
It is possible to do it, for example, using this very good package jmoiron.github.io/sqlx
There are many useful examples here jmoiron.github.io/sqlx
Specifically for your case, MapScan is suitable, here is an example:
rows, err := db.Queryx("SELECT * FROM place")
for rows.Next() {
results := make(map[string]interface{})
err = rows.MapScan(results)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question