TransWikia.com

QGIS: Prevent the Primary Key from incrementing when feature won’t be saved

Geographic Information Systems Asked by Jean Zombie on January 17, 2021

So, I have a PostgreSQL/PostGIS DB attached to my QGIS project (MacOS, 3.10.).

I start adding a feature and cancel the process w/o saving the form. When adding another feature my primary key increments by one even though the last feature wasn’t saved.

Is this avoidable? Meaning: Can I prevent the PK from being incremented when canceling a feature addition?

One Answer

Go to

<QGIS> | Settings | Options... | Data Sources | Data source handling

and see if Evaluate default values is active; if so, deactivate it.

QGIS can either request the default value (as per column definition) while editing (option active), or read the default value definition and pass it (or simply NULL) at save time (option inactive)!
A nextval call to a PostgreSQL Sequence ( the default action/value for SERIAL types) will increment regardless of transaction outcome!

Answered by geozelot on January 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP