I want to update the string length for a shapefile layer in QGIS. I've tried opening up Layer Properties and clicking edit but it won't let me change it manually. Also I've tried using the field calculator but I can't seem to get my head around it. I can create a new comment field (see "Comments_1"), but can't update the existing "Comments" to a character length of 254. The screenshot shows both windows I tried in.
2 Answers
If you want to change the length of a field you need to use the “Refactor fields” tool.
-
Which is under the Processing menu, Toolbox, expand "Vector table" then double-click on "Refactor fields". Aug 22 at 9:48
As in the comment from Binx, the main bit here is to calculate a new field and use the input boxes to set the field type and length:
Using 'length()' in the expression will return the actual number of characters in x, not reset a field to that length:
-
-
-
And the maximum string length in shapefile is just that 254 characters. Jun 14, 2022 at 20:36
Output field type=text
,Output field length=254
and in the expression section -"Comment"
. I am not aware how to change those properties in QGIS. I am sure you could do it in Python though.