How can using @row_number option or similar together the command "Create virtual field". It works very well with "Create new field", but doens't work with "Create virtual field".

  • 1
    You can't, Virtual Fields are purely expression based and row related, and are recalculated with each update. They have no concept of the table as a whole, necessary to keep track of the row count. – geozelot Jul 9 '19 at 8:34
  • Do you have any other ways to create a virtual field that contains the number of each row inserted in the table? Always up-to-date during row inclusion and delete edits? – Denilson Jul 9 '19 at 13:20
  • Instead of a virtual field, consider using a regular field with a default value. In layer properties > fields, use @row_number for the default value, and check the option to auto-update. – csk Jul 9 '19 at 18:30
  • I tried but in the option - Layer properties - Source fields there is no default value. So I tried the option - Layer properties - attributes form - Defauts - apply default value on update, but the @row_number command does not seem to exist on this form. – Denilson Jul 9 '19 at 20:46

As @ThingumaBob suggested, virtual fields do not have to be relied upon for assessing a table context.

For example in your case is no assurance that the order will remain the same after an update.

As a possible workaround, however, you could resort to use the $id function in a virtual field:

enter image description here

  • I tried to use $ ID, but my problem is that I do include and exclude rows in the table and the $ ID command always appends the ID, if I delete rows, the sequence is always a rising counter. – Denilson Jul 9 '19 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.