I have a simple layer in PostGIS created as follows:

    id serial PRIMARY KEY,
    geom geometry(LINESTRING, 31370),

To avoid duplicate information, I created a view with some information (eg length) derived from the geometry:

    SELECT *,
    ST_LENGTH(geom) AS length
    FROM layer;

I can access and edit the view myview in QGIS but whenever I want to save my edits, I got this error message: "Could not commit changes to layer. PostGIS error while adding features: ERROR: cannot insert into column "length" of view "myview". DETAIL: View columns that are not columns of their base relation are not updatable."

Is there a way to edit and save a view of a PostGIS table in QGIS?

  • 1
    Check this thread for creating editable views: gis.stackexchange.com/questions/201181/… Commented Nov 19, 2018 at 16:23
  • 1
    I think you can edit a view naturally in Postgres if your view doesn’t constitute columns that are being computed on the fly. In your instance you are recalculating the length and hence you get an error. In this case you are better off creating a materialized view and you can just refresh it when your underlying data changes. No need to worry about triggers Commented Nov 19, 2018 at 16:30
  • Thanks for the comments. It helps somehow but I got another error. BTW, it seems that defining triggers is better in this case.
    – juminet
    Commented Nov 21, 2018 at 16:01

1 Answer 1


You need an INSTEAD OF trigger to handle / ignore length attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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