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

First of all, sorry, I couldn't phrase my question better.

So I want to be able to add a new column in my attributes table, say B, and it's value should be 1 if Column A's value is 1 and 0 if Column A's value is 2. in other words:

If A==1 : B=1

elif A==2 : B=2 I couldn't figure out a way to do this using Field Calculator.

Thanks Trying to update "MineDeleteIt" values based on path_type

share|improve this question
After the THEN it should be 'Bike lane baby' and also 'some arbitrary text'. You need single quotes for strings – Nathan W Jan 23 '13 at 4:36
You are right. I had added double quotes and it didn't make any difference. Thanks a lot for your patience! – Pep Jan 23 '13 at 4:39
Double quotes are for column names. Single quotes for strings. – Nathan W Jan 23 '13 at 4:43
@NathanW Sorry for pushing this, but do if-else conditions work too? I'm getting errors, but if it's possible I'll figure it out myself... – Pep Jan 23 '13 at 4:50
Not yet. We haven't added support yet. Feel free to open at ticket at and assign it to me. I'm the only Nathan in the list. – Nathan W Jan 23 '13 at 5:07
up vote 2 down vote accepted

You can use a case statement to do that:

    WHEN "A" = 1 THEN 1 
    WHEN "A" = 2 THEN 2 

If you want everything else to match you can use ELSE

    WHEN "A" = 1 THEN 1 
    WHEN "A" = 2 THEN 2
    ELSE 0

This way everything that is not A=1 or A=2 will get assigned 0.

share|improve this answer
thanks for your answer. Can you tell me where should I enter it though? should I use field Calculator? Because it says invalid expression... – Pep Jan 22 '13 at 21:49
Which version of QGIS? – Nathan W Jan 23 '13 at 0:35
it's 1.8. are u able to do it with field calculator? – Pep Jan 23 '13 at 1:37
Yes. What does it say when you click (More INfo) – Nathan W Jan 23 '13 at 3:56
it say's : Parser Error: syntax error, unexpected COLUMN_REF, expecting WHEN or ELSE or END Eval Error: No root node! Parsing failed? – Pep Jan 23 '13 at 4:13

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.