我正在尝试将传入的表单值插入到 Heroku 上的 PostgreSQL 数据库表中。这是正在使用的 Go 函数:
func Insert(w http.ResponseWriter, r *http.Request) {
db := dbConn()
if r.Method == "POST" {
nameo := r.FormValue("name")
typeo := r.FormValue("asslia")
balanceo := r.FormValue("balance")
insForm, err := db.Prepare("INSERT INTO al(name, asslia, balance) VALUES( ? , ? , ? )")
if err != nil {
panic(err.Error())
}
insForm.Exec(nameo, typeo, balanceo)
log.Println("INSERT: Name: " + nameo + " | Type: " + typeo)
}
defer db.Close()
http.Redirect(w, r, "/", 301)
}
我不断收到pq: syntax error at or near ","该行的错误insForm, err := db.Prepare("INSERT INTO al(name, asslia, balance) VALUES( ? , ? , ? )")
该表之前是这样创建的:
CREATE TYPE types AS ENUM ('asset', 'liability');
CREATE TABLE IF NOT EXISTS al
(id SERIAL,
asslia TYPES,
balance MONEY,
name VARCHAR(64) NOT NULL UNIQUE,
CHECK (CHAR_LENGTH(TRIM(name)) > 0));
我究竟做错了什么?
慕尼黑8549860
相关分类