[GIS] Problem with PostgreSQL View layer in QGIS

postgresqlqgissql-view

I have a PostgreSQL table and view:

     CREATE TABLE lines (
      geom geometry(MultiLineString,4326),
      type character varying(254),
      login text,
      gid serial NOT NULL,
      CONSTRAINT lines_pkey PRIMARY KEY (gid))

    CREATE OR REPLACE VIEW lines_view AS 
     SELECT lines.geom,
        lines.type,
        lines.gid
       FROM lines;

    CREATE OR REPLACE RULE add AS
        ON INSERT TO lines_view DO INSTEAD  INSERT INTO lines (geom, type, login)
      VALUES (new.geom, new.type, "current_user"());

    CREATE OR REPLACE RULE del AS
        ON DELETE TO lines_view DO INSTEAD  DELETE FROM lines
        WHERE lines.login = "current_user"()::text AND lines.gid = old.gid;

     CREATE OR REPLACE RULE upd AS
      ON UPDATE TO lines_view DO INSTEAD  UPDATE lines SET geom = new.geom, type = new.type, login = "current_user"()
      WHERE lines.login = "current_user"()::text AND lines.gid = new.gid;

So, problem is when I load this lines_view in QGIS as layer and add lines, after saving I cannot use "node tool" to new lines ("Node tool: could not snap to a segment on the current layer"). But when I use move tool on them (just select "move feature(s)" button and click on new line) "node tool" start working as usual. Can some one help me with this?

Best Answer

You didn't mention qgis nor postgis version, qgis 2.10 doesn't let you edit table without a primary key - which would be the case of your view.

Related Question