5

I can not insert on an updateable view with QGIS,

CREATE TABLE foo (
  id serial PRIMARY KEY,
  mytext text,
  geom geometry(point)
);
CREATE VIEW bar AS TABLE foo;

When I map bar as a layer and try to create a new feature on it, I get,

Could not commit changes to layer bar

Errors: ERROR: 1 feature(s) not added.

  Provider errors:
      PostGIS error while adding features: ERROR:  null value in column "id" violates not-null constraint
    DETAIL:  Failing row contains (null, asdf, null).
4
  • 4
    Are you editing the view in QGIS? That's a whole different subject requiring back-end rules in PostgreSQL and you might want to see this post: gis.stackexchange.com/questions/88120/… Nov 14 '17 at 20:38
  • 2
    You need to create trigger INSTEAD OF for your view with incrementing gid (vibhorkumar.blog/2011/10/28/instead-of-trigger) Nov 15 '17 at 8:12
  • Even if the INSTEAD OF trigger is created, I do have the same problem too. I have to manualy enter something in the "gid" field. I could also leave it blank and the sequence does its job, but from a user point of view, it might be confusing. Nov 15 '17 at 22:51
  • @DPSSpatial no, that's using the rule system to create a PostgreSQL updateable views. That's still what PostgreSQL does under the hood, but this is with the autogenerated view (9.5+). Mar 30 '18 at 0:18
2

QGIS Bug #18586

Having researched this and recreated this myself. I've opened up a bug.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.