在GO中使用transaction.Stmt(sqlstatement).Exec(parameter)时是否可以记录最终查询?

Hi I am using database/sql package, and for example I have this:

var DeletePermissionStmt *sql.Stmt
DeletePermissionStmt, err = database.Prepare(`DELETE FROM permission WHERE permission_id=$1`)
if err != nil {
    log.Errorf("can't prepare delete permission statement: %s", err.Error())
}
transaction, err := database.Begin()  // assume postgres database is defined previously
if err != nil {
    log.WithFields(logFields).Errorf("can't start transaction: %s", err.Error())


    return err
}
_, err := transaction.Stmt(DeletePermissionStmt).Exec(permission_id)

I am succeeding in doing what I want to do except that I want to log the exact query that is used and that if I run it in postgres I will have the same result Is there anyway to do it?

Transaction uses standard SQL i.e. BEGIN / START TRANSACTION, COMMIT, ROLLBACK. However, prepared statements are specific to database server, e.g.

Taking log of exact query with database/sql will be difficult (or impossible). Query logging depends on implementation of the driver, for example https://github.com/jackc/pgx supports logging, but https://github.com/lib/pq doesn't support.