Bug report #2137
Wrong ID provided to the PostGIS on save
|Affected QGIS version:||Regression?:||No|
|Operating System:||Gentoo||Easy fix?:||No|
|Pull Request or Patch supplied:||Resolution:||fixed|
|Crashes QGIS or corrupts data:||Copied to github as #:||12197|
I'm trying to use qgis with my PostGIS database. I have only 3 tables for different kinds of components. So I've created a couple of updatable views to make a work with QGIS more comfortable and to keep my internal structure. But when I'm setting a unique ID to the element (in QGIS) I receive a complaints about duplicate ID.
For example: I have an empty view (but not empty table with elements), but I know - the ID=15 is unique, I create a new element in the layer associated with this view and set the ID to 15, but on save I receive error. After the empty record created manualy with ID=15 and I'm saving to this view - I see ID's started from 16. Inspite of provided data to ID field it is counted automaticaly.
#2 Updated by fsat - about 11 years ago
Schema is attached to the ticket, to populate it with sample data just execute the following statements.
insert into maps (ID, NAME) values(1, "map1");
insert into layers (ID, NAME, MAP_ID) values(1, "layer1", 1);
After that you can add LINESTRING layer in QGIS using view with name "map1_l1_l" and draw a line.
And after that add POINT layer in QGIS using view with name "map1_l1_s" and reproduce my error.
As you can see from section:
query := 'create or replace rule '|| view_name || 'i ' || '
as on insert to '|| view_name || '
do instead (
insert into layer_elements (layer_id, id, name) values('|| lid ||', NEW.id, NEW.name);
insert into ' || le ||' (id, the_geom) values(NEW.id, NEW.the_geom);
The ID is not calculated automaticaly, I'm using the provided one, without defaults.
PostGIS version - 1.4.0, Postgresql version - 8.2.14, QGIS version - 1.3.0
#5 Updated by Jürgen Fischer almost 11 years ago
Replying to [comment:5 jef]:
should be fixed in 8a66aee7 (SVN r12236) - hopefully without breaking something else.