0

I have a simple layer in PostGIS created as follows:

CREATE TABLE layer (
    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:

CREATE VIEW myview AS
    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/… – DPSSpatial Nov 19 '18 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 – kartoza-geek Nov 19 '18 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 Nov 21 '18 at 16:01

Your Answer

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

Browse other questions tagged or ask your own question.