I have a Multipolygon-Layer stored in a PostgreSQL/PostGIS database. The primary key field 'gid' is SERIAL. When trying to add a new polygon in QGIS (LYON 2.12.1 on OSX El Capitan), the attributes form shows me:
nextval('test_gid_seq'::regclass)
for the gid field (which is the correct sequence to autoincrement the field).
When I try to save the edits, I always get an error:
ERROR: duplicate key value violates unique constraint "test_pkey"
DETAIL: Key (gid)=(1) already exists.
This is strange, since the actual value in the sequence is 114. Why does QGIS tries to use 1? Is this a bug in QGIS? Or does anybody know how to avoid these problems?
create table test (id serial primary key, val int); insert into test values (1);insert into test values (1);
where the second insert fails withERROR: duplicate key value violates unique constraint "test_pkey" DETAIL: Key (id)=(1) already exists.
This, of course, is because there is no explicit field list. If the insert was insteadinsert into test (val) values (1);
then it works. I'm sure you know this, but I can't see any other way that this error could arise.