I am trying different queries in the Query Builder. Is there a way to comment the query? I tried with

/* */



without success :

An error occurred when executing the query. The data provider said: OGR[3] error 1: SQL Expression Parsing Error: syntax error


  • I have made a feature request of this question: http://hub.qgis.org/issues/10914

  • @Bernd V. observed that expressions are evaluated differently according to the format of the vector (see the [help] button in the Query builder for more information)

  • Welcome to GIS! Unless I'm mistaken, I don't think you can comment queries in the Query Builder.
    – Joseph
    Jul 17 '14 at 12:18
  • Is there an other way to build queries then (and comment them as required ?) (Thx for editing, it looks much better)
    – nebi
    Jul 17 '14 at 12:48

It doesn't work with ESRI shapefile. However, commenting in expressions works in QGIS 2.14 with SpatiaLite, SQlite and GeoPackage. For most other formats available in the Save as...-dialog, the query fails with an OGR-error.

Use -- for one-line comments and /* ... */ for multi-line comments

It turns the letters to a green color in the expression builder window and they seem indeed to be commented out!

  • Awesome! I don't have QGIS 2.8.2 to test but it is mentioned here so I believe you :) In which case, your answer should be accepted!
    – Joseph
    Jun 2 '15 at 12:18
  • and @Joseph: are you sure you're in the Query Builder? I can't reproduce it. It turns the letters to green but it still doesn't work (2.8.2-Wien).
    – nebi
    Jun 4 '15 at 8:11
  • @nebi - I also cannot reproduce it in the Query Builder (also installed 2.8.2 Wien). Only seems to work in the Field Calculator. Have you opened a ticket (feature request) for this?
    – Joseph
    Jun 4 '15 at 11:32
  • didn't test it beforehand in the Query Builder (sorry) but with rule based rendering expressions etc, cause I hardly ever use that thing. But here it works as well. Am on Linux Mint, maybe there is a difference/bug in Windows?
    – Bernd V.
    Jun 4 '15 at 12:22
  • Ha! Seems I found the difference. I was using it successfully with a Spatialite-Layer. Now I tested it with a ESRI-Shape ... and it fails!
    – Bernd V.
    Jun 4 '15 at 12:36

You can build queries by using the Query Builder or an alternative is to use the Expression string builder (Layer Properties > Style > select Rule-based > add a rule > insert your command in the Filter box or click the '...' button to bring up the string builder interface.

In both cases, I do not think QGIS supports the comments function when creating expressions for filters/queries:


  • True, with this way you can save your rules and import / export them ... But it's not as quick as commenting with some symbol at the beginning of the line. Copy / paste in the query Builder is tedious
    – nebi
    Jul 17 '14 at 13:58
  • 2
    @nebi, you could always send a request for this to be implemented in future updates.
    – Joseph
    Jul 17 '14 at 14:11
  • Yes, I want to do it
    – nebi
    Jul 17 '14 at 14:12

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.