[Qgis-user] Autogeneration id codes
Erik Wienhold
ewie at ewie.name
Tue May 2 09:25:03 PDT 2023
> On 02/05/2023 17:28 CEST Riccardo via QGIS-User <qgis-user at lists.osgeo.org> wrote:
>
> I have some tables already created that have a column with autogeneration id
> codes.
I assume this is about the primary key column. What database system do you use?
> From self-generation I often don’t get codes that start from 1 onwards but
> start with other numbers.
That's the point of autogenerated IDs that they are not reused. You can restart
the underlying sequence, depending on the database system.
> I made some tests and I noticed that if I create a table and add 10 lines the
> autogeneration creates id codes from 1 to 10. If I delete these lines to empty
> the table when I create a new line Qgis autogenerates that with the code 11,
> it seems that Qgis keeps in memory the number/id code of the created elements,
> and keep the numbering as a fixed counter.
>
> How can I impose a autogeneration of id codes starting from 1?
Why do you want to reuse previously generated IDs? QGIS (or the database for
its part) must ensure that generated IDs are unique. Two or more users
inserting rows in the same table at the same time should get different IDs.
If QGIS or the database would generate ID 1 because it's not used by any row,
users would insert their rows with the same ID and get a primary key constraint
violation.
--
Erik
More information about the QGIS-User
mailing list