Hello,
When I do the below insert statement, the sql result returned is
2012/07/12 20:36:50 INSERT INTO books (id, title, price) VALUES (912312444, 'My title', 20) RETURNING id
2012/07/12 20:36:50 sql: no rows in result set
---
The postgres log gives explicit details
LOG: execute 1: INSERT INTO books (id, title, price) VALUES (912312444, 'My title', 20) RETURNING id
ERROR: duplicate key value violates unique constraint "books_pkey"
DETAIL: Key (id)=(912312444) already exists.
STATEMENT: INSERT INTO books (id, title, price) VALUES (912312444, 'My title', 20) RETURNING id
LOG: unexpected EOF on client connection
----
my code is
var id int64
err := db.QueryRow(sqlStr).Scan(&id)
if err != nil {
//panic(err)
log.Println(err.Error())
return
}
---
I am getting detailed error if I use Exec()
2012/07/12 18:40:14 INSERT INTO books (id, title, price) VALUES (12312444, 'My title', 20)
2012/07/12 18:40:14 pq: C:"23505" D:"Key (id)=(12312444) already exists." F:"nbtinsert.c" M:"duplicate key value violates unique constraint \"books_pkey\"" L:"397" S:"ERROR" R:"_bt_check_unique"
But, I like to use Query to get the newly inserted row id.
Is there a way I can get more explicit error than (sql: no rows in result set)
thanks
bsr.