LoginSignup
0
0

Goプログラミング実践入門を読んで[随時更新]

Last updated at Posted at 2023-05-20

Db.Where("author = &1", "俺やろ").First(&readPost)でエラー

エラー内容

[2023-06-01 22:46:17]  pq: operator does not exist: & integer 
panic: runtime error: index out of range [0] with length 0

問題のコード

実行環境は、PostgreSQL14
プレースホルダーの問題の様でGoでは$1ではなく?で基本的にコーディングすればよい

// 動かない
Db.Where("author = $1", "俺なのか").First(&readPost)

// 動く
Db.Where("author = ?", "俺なのか").First(&readPost)

対応リポジトリ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0