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 replace selected string values in an attribute table, eg. "Text1" for "Text2" (QGIS 1.8.0), patriculary for those rows with NULL values. I have been trying to use the replace expression (and any other that I have found) with no luck.

Are there any wildcard characters that I may be able to use in future?

share|improve this question
check also regexp_replace() function as described in… – underdark Dec 3 '12 at 8:33
up vote 8 down vote accepted

You could try a case when expression:

case when "Column_1" is NULL then  replace("Column_2",'Text2','Text1') else "Column_2" end

Using the 'or' expression, you can add multiple columns with NULL-values to the code.

case when "Column_1" is NULL or "Column_3" is NULL then  replace("Column_2",'Text2','Text1') else "Column_2" end


If you want to replace NULL, forget the replace-expression (it only works for strings and NULL is no string). Try this exact code:

case when "Feature" is NULL then '12_1' else "Feature" end
share|improve this answer
Thanks for the fast reply. How would the 'case when' expression work when simply wanting to update values in a field, rather than creating a new field? – mastorey Dec 2 '12 at 19:51
Just select the field you want in the Field Calculator instead of choosing "Create new field". The code stays the same. – GR_ Dec 2 '12 at 19:55
Thanks again. I think the problem may lie in the fact that my attribute table has but one field? I am trying to update the values of selected polygons, i.e. from a NULL value to a single alphanumeric tag. Whatever, I wonder, happenned to the 'find and replace' function of earlier QGIS releases. – mastorey Dec 2 '12 at 20:10
This should do the trick: case when "Column_1" is NULL then 'Text1' else "Column_1" end – GR_ Dec 2 '12 at 20:15
Thanks but I'm still not getting any changes to the attribute table. Based on the code you've suggested, I'm entering the following: case when "Feature" is NULL then replace("Feature",'NULL','12_1') else "Feature" end I've also tried to express NULL as both 'NULL' and '' without success. Any further help would be very welcome and most appreciated. – mastorey Dec 2 '12 at 20:36

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.