15

I am confused concerning the quotation marks syntax ('single' vs "double") in QGIS.

I know something about the quotation marks and the way they are applied in Python scripting (i.e. comments, strings etc.).

There are even some related questions:

Nevertheless, I would like to clarify the details regarding the quotation marks ('single' vs "double") in the scope of QGIS.

For instance, if I type something in the Expression dialogue I will have a different output.

  • "something", it is written as

something1

The Output is NULL.

  • 'something', it is shown as

something2

The output is 'something' as a string.

What is the syntax or meaningful difference between quotation marks ('single' vs "double") in QGIS?

I do not know if there are any circumstances when other types of quotation marks are used in QGIS like the triple quotation marks in Python.

4 Answers 4

24

Double quotes indicate that the string represents the name of an attribute while a single quote is a literal string.

So in your first case you get NULL because you don't have an attribute called something.

1
  • 9
    My mnemonic for this is "Single for Strings, Double for Data". So to compare a data field with a string value you'd use "name" = 'Fred'
    – Spacedman
    Commented Nov 6, 2018 at 19:31
16

Here is the answer directly from QGIS help:

column name "column name" → Value of the field column name, take care to not be confused with simple quote, see below

'string' → a string value, take care to not be confused with double quote, see above

9

Double marks refer to columns in the attribute table, single marks to a string value. E.g. CASE WHEN "something" > 100 THEN 'a lot' ELSE 'not so much' END checks the size of integer values in your column and adds a string to fields in the attribute table based on that size.

4
  • 1
    Does this mean that the value of an attribute "something" is bigger than string '100'?
    – user30184
    Commented Nov 6, 2018 at 14:49
  • 1
    If the value of a field in column "something" is bigger than 100, then I write "a lot" into a new column, else the other text is written.
    – Erik
    Commented Nov 6, 2018 at 15:13
  • 1
    I asked because I do not know the syntax that QGIS is using. In databases '100' means a string and then '101'>'100' but also '99'>'100' because 9 comes after 1 in alphanumeric order. Does QGIS make difference and is it possible to compare by numbers WHEN "something" > 100?
    – user30184
    Commented Nov 6, 2018 at 17:10
  • 1
    Actually '100' really means a string, sorry, gonna edit it. Comparison of numbers is possible, yes.
    – Erik
    Commented Nov 7, 2018 at 8:05
0

The explanation in the 3.34 docs made it very clear for me.

  • ' - single quote: A literal string. Functions usually take a literal string as input.
  • " - double quote: Gives you the value of the quoted element. So "height" gives you the value for the current row in the column "height"! Or returns NULL if no column "height" exists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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