I am using QGIS and want a query that will change a text value "TIPPERARY SOUTH" AND "TIPPERARY NORTH" to "TIPPERARY". Both TIPPERARY NORTH and TIPPERARY SOUTH are contained within a field called COUNTY. Is it possible for me to only update these entries within the COUNTY field, or do I need to create another field to do this. There are over 400 entries with both these names so it would take to long to do manually.
I have created the COUNTYNAME field if this is required but I would also need a query to Transfer across other values from the COUNTY field. This would be a like for like for the other entries e.g. I want value "DUBLIN" in "COUNTY" field to display as "DUBLIN" in the "COUNTYNAME" field.
-
1The current answers below would also change "TIPPERARY WEST" to "TIPPERARY". As long as NORTH and SOUTH are the only TIPPERARYs (sorry, I don't know the place, its a long way...) then they'll do the job.Spacedman– Spacedman2025年05月06日 08:58:01 +00:00Commented May 6 at 8:58
-
Thank you very much for the help!Declan McG– Declan McG2025年05月06日 19:26:48 +00:00Commented May 6 at 19:26
2 Answers 2
We can update the existing field where the original values are stored but I suggest you update a separate field as not to risk loss of data.
We can update via the Field Calculator:
rc Layer > Layer Properties > Fields > Field Calculator.
In your case we can apply the following in the field calculator expression for the layer:
CASE
WHEN "COUNTY" LIKE 'TIPP%' THEN 'TIPPERARY'
ELSE "COUNTY"
END
This will look for all text in the "COUNTY" field that start with 'TIPP' and set the new value to 'TIPPERARY'. For all other cases it will copy the original COUNTY value across, e.g. 'DUBLIN' will copy across as 'DUBLIN'.
-
Thank you so much for the quick reply, this query was perfect!Declan McG– Declan McG2025年05月06日 19:26:00 +00:00Commented May 6 at 19:26
Update the field or create a new field with Field calculator using this expression:
regexp_replace ("COUNTY", 'TIPPERARY.*', 'TIPPERARY')
It uses Regular Expressions with function regexp_replace()
to search for content in field COUNTY
containing the text TIPPERARY
and replaces (removes) all characters after this textstring, using .*
(dot for any character
and quantifier *
for 0 or more of these).
Fields that do not contain TIPPERARY
remain unchanged.
-
Thank you very much for this!Declan McG– Declan McG2025年05月06日 20:51:30 +00:00Commented May 6 at 20:51
-
1You're welcome. As a new user, please be adviced that this site tries to avoid "thank you" messages. Instead, it encourages you to accept the answer and/or upvote it: click the checkmark right to the answer to accept it - see: gis.stackexchange.com/help/someone-answers Just click the checkmark, see here: meta.stackexchange.com/questions/5234/…Babel– Babel2025年05月06日 22:35:26 +00:00Commented May 6 at 22:35