-
Notifications
You must be signed in to change notification settings - Fork 911
Rows.Next
panic due to index out of range
#1253
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
Comments
I've never used gorm. Can you reproduce with just pgx? |
I have a similar issue when calling rows.Values I get a panic My code package http
import (
config "http_client3/package/config"
"http_client3/package/db"
"log"
)
// Connection db and exec proc
func (obj *GetPostOgbject) exec(sql string, args string) error {
//Get Params for connection db
params, err := config.GetFullParam([]string{"db_user", "db_password", "db_host", "db_port", "db_dbname", "db_sslmode"})
if err != nil {
obj.set_response("", &ErrorObject{"DB", "9", "server side error"})
return err
}
// Connection to data base
db, err := db.Connection(params)
if err != nil {
obj.set_response("", &ErrorObject{"DB", "9", "server side error"})
return err
}
log.Println("sql:", sql)
log.Println("args:", args)
row, err := db.PostgreSQL.Query(sql, args)
if err != nil {
obj.set_response("", &ErrorObject{"DB", "9", "server side error"})
return err
}
//Connection db close
defer func() {
if err := db.PostgreSQL.Close(); err != nil {
log.Println("error close connection db", err)
}
}()
s, err := row.Values()
if err != nil {
obj.set_response("", &ErrorObject{"DB", "9", "server side error"})
return err
}
log.Println(s)
return nil
} Result
|
@R2D2Dan I do not see a call to |
And you should always call Next() before Values()? |
Yes. You always must call |
I’m closing this one since we don’t have a reproducible example with just pgx. |
@microyahoo were you able to find the reason for the reported issue? Facing the same issue with gorm, would appreciate any pointers. |
hi @syed-shah-zepto, If I remember correctly, if multiple goroutines access the database at the same time under the one transaction, an error will be reported |
thanks @microyahoo. How did you get around this? |
@syed-shah-zepto After moving the access to the database outside the goroutines, the problem did not reappear. |
@syed-shah-zepto @bfontaine |
@Froctnow I doesn't have INSERT INTO ... RETURNING in one transaction, but i have many goroutines to using UPDATE in the same transaction. I always meeting the error. But if a only have SELECT the error doesn't appear. |
Uh oh!
There was an error while loading. Please reload this page.
The version of pgx, gorm and golang
The following code will be panic due to
panic: runtime error: index out of range [0] with length 0
The log snippet is as follows:
The text was updated successfully, but these errors were encountered: