conn.Exec() function has a bug.
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
Hello, for past 2 days i'm learning how to use your driver and i'm found an interesting thing. When i use "Exec" function and try to insert a row to database, it inserts that row 2 times. Code is like below:
```go
package main
import (
"context"
"os"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)
func InsertRow(conn *pgxpool.Conn) {
_, err := conn.Exec(context.Background(), "INSERT INTO goschema.goprods(id, ptype, price, name) VALUES(16, 'Food', '70', 'Bla Bla Food')")
if err != nil {
fmt.Fprintf(os.Stderr, "İnserting Failed: %v\n", err)
os.Exit(1)
}
}
func main() {
conn, err := dbpool.New(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
defer dbpool.Close(context.Background())
singleConn, err := dbpool.Acquire(context.Background())
if err != nil {
fmt.Print(err)
}
InsertRow(singleConn)
singleConn.Release()
}
```
My Go Version is 1.20.4
My pgx version v5.4.0
My Postgres Version is 15
When i use "Query" function for inserting row that worked correct but "Exec" function isn't.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the InsertRow and main functions in the supplied Go example, then reproduce the INSERT using pgx v5.4.0 against PostgreSQL 15 while comparing Exec and Query. Review the six-comment thread for missing reproduction details; done means establishing whether pgx executes the statement twice and recording a minimal confirmed cause.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100