Bug report #16891
$rownum returns 0 in field calculator
Status: | Closed | ||
---|---|---|---|
Priority: | High | ||
Assignee: | - | ||
Category: | Field calculator | ||
Affected QGIS version: | 2.18.11 | Regression?: | Yes |
Operating System: | Windows 7 32bits | Easy fix?: | No |
Pull Request or Patch supplied: | No | Resolution: | invalid |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 24790 |
Description
In QGIS 2.18.10, the $rownum function allways returns 0 in the field calculator.
As per #12174, it should return 0 in the expression field, but not in the field calculator.
Furthermore, the preview shows 1.
Is this some kind of regression ?
History
#1 Updated by Giovanni Manghi over 7 years ago
- Status changed from Open to Feedback
- Priority changed from Normal to High
I just tested and does now happen here on Linux and Win7 with QGIS 2.18.10. Does it happen with any data of yours? tried without 3rd party plugins?
#2 Updated by A L over 7 years ago
I tried on at least two different layers, but both where postgis layers.
The weird part that might give you a clue : the $rownum function is not in the functions list under "record". It's not in the list at all in fact. It is not shown in red though, so it is somehow recognized.
How do you try without third party plug-ins? Is there some kind of safe mode? (sorry, new user here)
#3 Updated by Giovanni Manghi over 7 years ago
A L wrote:
I tried on at least two different layers, but both where postgis layers.
The weird part that might give you a clue : the $rownum function is not in the functions list under "record". It's not in the list at all in fact. It is not shown in red though, so it is somehow recognized.
How do you try without third party plug-ins? Is there some kind of safe mode? (sorry, new user here)
just tried with PostGIS layers on both Linxu and Windows and 2.18.10, works as expected (and starts from 1).
To start without plugins
qgis --noplugins
#4 Updated by Giovanni Manghi over 7 years ago
- Affected QGIS version changed from 2.18.10 to 2.18.11
#5 Updated by A L over 7 years ago
OK, I tried without plugins and it still doesn't work.
I almost got it to work when I created a "real" field instead of a "virtual field" in the fiels calculator.
Then the layer went into edit mode, and the new field was correctly computed and displayed. Of course, trying to exit edit mode did not work, since QGis tried to save the changes to the PostGIS layer, which it could obiviously not do.
If I do the exact same thing with a virtual field, it does not work at all.
I still find it very weird that I do not have a "$rownum" function in the functions list :
#6 Updated by Giovanni Manghi over 7 years ago
- File Screenshot_20170807_134950.png added
A L wrote:
OK, I tried without plugins and it still doesn't work.
I almost got it to work when I created a "real" field instead of a "virtual field" in the fiels calculator.
Then the layer went into edit mode, and the new field was correctly computed and displayed. Of course, trying to exit edit mode did not work, since QGis tried to save the changes to the PostGIS layer, which it could obiviously not do.
If I do the exact same thing with a virtual field, it does not work at all.I still find it very weird that I do not have a "$rownum" function in the functions list :
see attached image. The fact you are finding issues with this and not seeing the $row_num function suggests you have local issues. Try do cleanup (remove the .qgis2 folder, remove qgis registry entries) and try again.
#7 Updated by Nyall Dawson over 7 years ago
Rownum is not available in virtual fields - that's why it's not shown in the expression builder when creating a virtual field.
#8 Updated by A L over 7 years ago
The fact you are finding issues with this and not seeing the $row_num function suggests you have local issues. Try do cleanup (remove the .qgis2 folder, remove qgis registry entries) and try again.
I did that and installed the latest 2.18.11. No change.
Rownum is not available in virtual fields - that's why it's not shown in the expression builder when creating a virtual field.
I tried with a regular field and it's not shown either.
I also tried on a shapefile layer and it's still not there.
My PostGIS layer is a view, not a table, so a regular field does not work. That's where my problem is obviously. I need some way to add a unique id field to a read-only layer.
#9 Updated by Nyall Dawson over 7 years ago
Try $id instead of rownum. Regardless of the data source, rownum is not available in virtual fields.
#10 Updated by A L over 7 years ago
Yes, I already tried that, but $id does not work very well when you filter the layer (i.e. not starting at 1, and holes in the series).
I'm a bit surprised that there is not such a function in QGis, since it is quite standard to have numbers on the map and the corresponding description in the legend. That is what one can find on any web map that displays retail stores of a specific brand for instance.
#11 Updated by Giovanni Manghi about 7 years ago
- Resolution set to invalid
- Status changed from Feedback to Closed
A L wrote:
Yes, I already tried that, but $id does not work very well when you filter the layer (i.e. not starting at 1, and holes in the series).
I'm a bit surprised that there is not such a function in QGis, since it is quite standard to have numbers on the map and the corresponding description in the legend. That is what one can find on any web map that displays retail stores of a specific brand for instance.
Please file a feature request instead. Cheers!