-
Notifications
You must be signed in to change notification settings - Fork 923
-
I am seeing sql: no rows in result set
for a quite simple statement that works when I run it on psql CLI.
Is there anyway of printing out what raw SQL is executed , so I can just check formatting etc?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 1 reply
-
The raw query is available in the generated code. That should show you exact what query is being run.
Beta Was this translation helpful? Give feedback.
All reactions
-
If you're using pgx, I use this to log all the queries:
cc, err := pgxpool.ParseConfig(config.GetDSN())
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
if *queryLogging {
cc.ConnConfig.Logger = logrusadapter.NewLogger(&logrus.Logger{
Out: os.Stderr,
Formatter: new(logrus.JSONFormatter),
Hooks: make(logrus.LevelHooks),
Level: logrus.InfoLevel,
ExitFunc: os.Exit,
ReportCaller: false,
})
}
If you don't use pgx, you could relatively easily intercept the queries as they're being sent to the database by implementing a DBTX that logs and then sends them on to the database.
Beta Was this translation helpful? Give feedback.
All reactions
-
In pgx/v5 it's ConnConfig.Tracer and tracelog.
Beta Was this translation helpful? Give feedback.