go-pg is PostgreSQL client and ORM for Golang. To show generated queries we have to implement some hooks. There are multiple posts about this in issues, this is an exact working example of it.
Source code viewer
import ( "fmt" "context" ) type dbLogger struct { } func (d dbLogger) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Context, error) { return c, nil } func (d dbLogger) AfterQuery(c context.Context, q *pg.QueryEvent) error { fmt.Println(q.FormattedQuery()) return nil } func main() { // ... // After add after database connection "db := pg.Connect(options)' db.AddQueryHook(dbLogger{}) // ...Programming Language: Go