I think the QGis code should not have this specific behaviour and should follow the standards.
If the key doesn't contain any informations and is just a number, then OK we can explicitly tell QGis to use a PostgreSQL sequence to create this arbitrary number. In my case, the values of the key come from an other application and I have to type these values to link the geometrical objects to the database informations. I found a workaround : if I change the field type of the key from integer to bigint then everything works as attended... QGis doesnt tries anymore to give a value when we don't need it. But this is not very logical isn't it? Fabrice 2012/5/15 Bernhard Ströbl <bernhard.stro...@jena.de> > Hi Fabrice, > > I think this is the intended behaviour. If you leave it to the user to > enter the primary key then the db might complain about non-unique keys. On > the other hand why would you _want_ to assign a certain key? A key is just > a technical field used to identify a dataset. It should not contain any > information. > On my db I have three tables (point, line, polygon) that insert into the > same table representing a n:m relation. I use a sequence on the db and a > trigger to assign the next sequence value on INSERT. Apart from that I have > no need to interfere with my pk values and I am glad, that QGIS takes care > of that. > > Bernhard > > Am 15.05.2012 13:07, schrieb F T: > >> >> Hi all, >> >> We are not able to set explicitly the value of an integer primary key >> field. >> >> It is possible to set this value with pgAdmin. >> But when the feature is created with QGis, it takes the next max value >> of the field and not the spécified value... >> >> To reproduce this strange behaviour : >> >> -- create a table in the schema public with an integer primary key >> CREATE TABLE the_table >> ( >> the_key integer NOT NULL, >> the_obs character varying(150), >> geom geometry, >> CONSTRAINT the_table_pkey PRIMARY KEY (the_key), >> CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2), >> CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = >> 'MULTILINESTRING'::text OR geom IS NULL), >> CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 2154) >> ) >> WITH ( >> OIDS=TRUE >> ); >> -- spatialize the table >> INSERT INTO geometry_columns(f_table_**catalog, f_table_schema, >> f_table_name, f_geometry_column, coord_dimension, srid, "type") >> VALUES('', 'public', 'the_table', 'geom', 2, 2154, 'MULTILINESTRING'); >> >> Then in QGIS : >> - add this table to a project >> - create 1 line with the_key=100 and save the edition -> open the >> attribute table and you see the_key=0 >> - create 1 line with the_key=102 and save the edition -> open the >> attribute table and you see the_key=1 >> >> If I modify the value of the_key in pgAdmin, by example put the value >> 1000 instead of 1, then the next line created with QGis will have the >> value 1001. >> >> Any help is welcome ! >> Thanks >> >> Fabrice >> >> >> >> >> >> ______________________________**_________________ >> Qgis-user mailing list >> Qgis-user@lists.osgeo.org >> http://lists.osgeo.org/**mailman/listinfo/qgis-user<http://lists.osgeo.org/mailman/listinfo/qgis-user> >> >> >> > > ________ Information from NOD32 ________ > This message was checked by NOD32 Antivirus System for Linux Mail Server. > http://www.nod32.com >
_______________________________________________ Qgis-user mailing list Qgis-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-user