Ian Bicking: the old part of his blog

Comment

A trick I use to get fast at the generated SQL query: I put a "dtml-raise string" around the SQL stuff directly in the ZSQL method. That throws an exception with the SQL that will be sent to the database as the error value.

Another option is turning on logging in your database (easily done with PostgreSQL).
Comment on Z SQL Rant
by Georg Bauer