Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is it possible to see the raw SQL statements? #1408

Unanswered
lukehinds asked this question in Q&A
Discussion options

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?

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

The raw query is available in the generated code. That should show you exact what query is being run.

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
1 reply
Comment options

In pgx/v5 it's ConnConfig.Tracer and tracelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /