Postgres/pq bulk insert syntax issue
KeithAlt opened this issue · comments
Dependencies:
"github.com/gin-gonic/gin"
_ "github.com/lib/pq"
"github.com/rocketlaunchr/dbq/v2"
"net/http"
Code of issue:
psqlInfo := fmt.Sprintf("%s://%s:%s@%s:%s/%s?sslmode=%s",
"postgres", "postgres", "postgres", "localhost", "5432", "", "disable",
)
db, _ := sql.Open("postgres", psqlInfo)
type Row struct {
Username string
Password string
}
users := []interface{}{
dbq.Struct(Row{"John", "abc123"}),
dbq.Struct(Row{"Mark", "abc123"}),
dbq.Struct(Row{"David", "abc123"}),
}
stmt := dbq.INSERTStmt("accounts", []string{"username", "password"}, len(users))
_, err := dbq.E(ctx, db, stmt, nil, users) // <- always results in syntax error
if err != nil {
panic(err) // <- pq: syntax error at or near ","
return
}
Output: pq: syntax error at or near ","
Consistently results in a syntax error.
If the cause is the above code, let me know 👍
You need to set option to postgres mode
You need to set option to postgres mode
My mistake.
Thanks! 👍
Also use a faster postgres driver instead of pq