Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use the Data Defined symbology in QGIS ver 2.2. Some of my data has single quotes/apostrophes.

Since the string must use single quotes, is there an escape option I can use for the field calculator or for the data defined settings field?

So, I'm trying to use something like this:

WHEN "NAME" = 'WILSON'S' THEN '0,75,224'

How do you build an expression around a string that may have a single quote or apostrophe?

Thanks. QGIS Valmiera 2.2 Windows 7 - 32 bit

share|improve this question
up vote 4 down vote accepted

Using the escaping by simply doubling the single quote works for me:

WHEN "NAME" = 'WILSON''S' THEN '0,75,224'

Double quotes in the field value don't need escaping:

WHEN "NAME" = 'WILSON"S' THEN '0,75,224'

and I'm not sure if they are allowed in field names. Surely not in shapefiles.

Works at least on Windows.

share|improve this answer
brilliantly simple, thanks! – mike May 6 '14 at 18:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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