Re: [Qgis-user] Autogeneration id codes
> On 02/05/2023 17:28 CEST Riccardo via QGIS-User > 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 ___ QGIS-User mailing list QGIS-User@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Re: [Qgis-user] Autogeneration id codes
Hi Riccardo, Have you tried, after you delete your rows, disabling editing and then enabling editing again before you add your new rows? Also have a look at this https://gis.stackexchange.com/questions/132346/is-there-a-way-of-auto-increment-for-the-id-column-in-qgis Regards, Richard. -- Richard McDonnell MSc GIS, FME Certified Professional FRM Data Management -- Oifig na nOibreacha Poiblí Office of Public Works Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36 Jonathan Swift Street, Trim, Co Meath, C15 NX36 -- M +353 87 688 5964 T +353 46 942 2409 https://gov.ie/opw -- To send me files larger than 30MB, please use the link below https://filetransfer.opw.ie/filedrop/richard.mcdonn...@opw.ie Email Disclaimer: https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/ -- MSc GIS, FME Certified Professional -- Oifig na nOibreacha Poiblí Office of Public Works Sráid Jonathan Swift, Baile Átha Troim, Co na Mí, C15 NX36 Jonathan Swift Street, Trim, Co Meath, C15 NX36 -- M +353 87 688 5964 T +353 46 942 2409 https://https://gov.ie/opw<https://www.opw.ie> -- Email Disclaimer: https://www.gov.ie/en/organisation-information/439daf-email-disclaimer/<https://www.opw.ie/en/disclaimer/> From: QGIS-User On Behalf Of Riccardo via QGIS-User Sent: 02 May 2023 16:28 To: Riccardo via QGIS-User Subject: [Qgis-user] Autogeneration id codes Good morning to all, first I would like to thank Bernhard Ströbl, Richard McDonnell, Andrea Giudiceandrea and Bernd Vogelgesang for suggestions related to some of my previous posts. Now I have another problem. I have some tables already created that have a column with autogeneration id codes. >From self-generation I often don't get codes that start from 1 onwards but >start with other numbers. 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? Many many thanks! Best Regards. Riccardo. ___ QGIS-User mailing list QGIS-User@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
[Qgis-user] Autogeneration id codes
Good morning to all, first I would like to thank Bernhard Ströbl, Richard McDonnell, Andrea Giudiceandrea and Bernd Vogelgesang for suggestions related to some of my previous posts. Now I have another problem. I have some tables already created that have a column with autogeneration id codes. >From self-generation I often don’t get codes that start from 1 onwards but >start with other numbers. 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? Many many thanks! Best Regards. Riccardo. ___ QGIS-User mailing list QGIS-User@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user