-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
erattacorrect in next reprint.correct in next reprint.
Description
ページ番号:p214(初版)
セクション番号:9.6.1
内容タイトル:プリペアードステートメントを使う
誤っている内容:
- プリペアードステートメントの構築において、構造体のフィールド数と割当てたいプレースホルダーの数が一致していない
yyyy/MM/dd hh:mm:ss sql: expected 3 arguments, got 2 exit status 1
正しい内容:
nullやcurrent_timestampで埋める
stmt, err := tx.PrepareContext(ctx, `
INSERT INTO users(
user_id,
user_name,
created_at
) VALUES (
$1, $2, null
);`)その他コメント:
-
tx.ParpareContextとサンプルコードにあるが、*Txがあることが前提なので、接続とトランザクション開始が省略されているconn, err := sql.Open("pgx", "host=localhost port=5432 user=testuser dbname=tesstdb password=pass sslmode=disable") if err != nil { log.Fatal(err) } defer conn.Close() tx, err := conn.BeginTx(ctx, nil) if err != nil { log.Fatal(err) }
Metadata
Metadata
Assignees
Labels
erattacorrect in next reprint.correct in next reprint.