对于这张表,
# \d table
Table "public.table"
Column | Type | Collation | Nullable | Default
------------+-----------------------------+-----------+----------+--------------------
id | uuid | | not null | uuid_generate_v4()
my_field | hstore | | |
Indexes:
"table_pkey" PRIMARY KEY, btree (id)
Run Code Online (Sandbox Code Playgroud)
如何使用lib/pq更新 my_field ?我尝试跟随,
package "main"
import (
"os"
"database/sql"
_ "github.com/lib/pq"
)
func main() {
postgresConn, _ := sql.Open("postgres", os.Getenv("DB_CONN_URL"))
id := "024b54f2-a477-4715-984c-896bf0446dcf"
data := map[string]string{"data": "data"}
postgresConn.QueryRow("UPDATE table SET my_field = $1 WHERE id = $2", data, id)
}
Run Code Online (Sandbox Code Playgroud)
我不确定可以使用哪种其他类型。