Is possible to dump a query made on a twig template for a statement like this one for example:


Can we some how see the actual SQL query ?


You can see each SQL query that is run for a page by turning devMode on and opening your console to read the 'Profiling Summary Report'.

You can see a total query count and each query beings with system.db.CDbCommand.query.

I'd advise maybe isolating the twig code on its own template to avoid having to work out which query was a result of the twig code you're after.

  • You can also try to filter the rows returned to the console to find the right one. In this example using "homepage" as a search term. – carlcs Jan 12 '17 at 15:11
  • Yeah this actually what i did, i isolated the twig code but instead of looking at the 'Profiling Summary Report' i used a plugin named Query log.The 'Profiling Summary Report' is much easier cause no extra plugin is needed. – nickGR Jan 13 '17 at 10:42

In Craft 3 you can use getRawSql() at the end of the element query.

{% set entries = craft.entries.section('blog').getRawSql() %}

{{ entries }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.