Per row commit when editing PostGIS data with QGIS, with PostGIS triggers checking inserted dataHow to update...

How can I make my BBEG immortal short of making them a Lich or Vampire?

How to draw the figure with four pentagons?

Today is the Center

In a spin, are both wings stalled?

Why doesn't H₄O²⁺ exist?

What is a clear way to write a bar that has an extra beat?

What is the word for reserving something for yourself before others do?

What do you call someone who asks many questions?

Is there a hemisphere-neutral way of specifying a season?

What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?

Did Shadowfax go to Valinor?

Why is consensus so controversial in Britain?

How do conventional missiles fly?

A reference to a well-known characterization of scattered compact spaces

Is it canonical bit space?

Took a trip to a parallel universe, need help deciphering

Western buddy movie with a supernatural twist where a woman turns into an eagle at the end

Alternative to sending password over mail?

Will google still index a page if I use a $_SESSION variable?

What about the virus in 12 Monkeys?

What does it mean to describe someone as a butt steak?

What is the most common color to indicate the input-field is disabled?

How can saying a song's name be a copyright violation?

I would say: "You are another teacher", but she is a woman and I am a man



Per row commit when editing PostGIS data with QGIS, with PostGIS triggers checking inserted data


How to update attribute values of points outside an area?update tables data dynamicallyInsert geometric data to a column from coordinate values in double precisionidentify subgraphs within planet_osm_line tableIssues with QGIS WFS editing/PostGIS renderingAdd individual fields to delete-log-trigger when deleting PostGis-Objects via QGisHow to use interacting PostgreSQL/PostGIS triggers in QGIS to create multiple labels on polygons?QGIS crashes when using PostgreSQL/PostGIS triggersEditable views in QGIS - update affects the wrong rowLines sometimes disappear when editing Postgis layer in QGIS 2.16






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have a PostGIS trigger assuring that records with a Point geometry inserted in a table fall within Polygons in another table.



Simple example:



-- Trigger function
CREATE OR REPLACE FUNCTION check_pointWithinPolygon()
RETURNS trigger AS $body$
BEGIN
IF TG_OP = 'INSERT'
THEN
IF ((SELECT count(*) FROM (SELECT poly.id FROM poly WHERE st_Within(NEW.geom, poly.geom)) as foo) > 0) THEN
RETURN NEW;
ELSE
RAISE EXCEPTION 'inserted feature ID:% is not within a poly', NEW.id;
END IF;
END IF;
END;
$body$ LANGUAGE plpgsql;
COMMIT;


-- apply the trigger function in a trigger
CREATE TRIGGER myPointInPoly BEFORE INSERT OR UPDATE
ON points FOR EACH ROW
EXECUTE PROCEDURE check_pointWithinPolygon();
COMMIT;


All this works well. I am using QGIS to edit the layer. Some point fall within polygons ( ok) some outside ( and are caught by the trigger). The problem comes when QGIS "save edits" committs the changes.



Currently, all edits are discarded if even a single record is not accepted. I would like to commit per row, so that those that are correct, are inserted. I am not sure whether this is something that can be caught in the trigger logic ( likely), or also needs reflection in the QGIS commit code.










share|improve this question





























    0















    I have a PostGIS trigger assuring that records with a Point geometry inserted in a table fall within Polygons in another table.



    Simple example:



    -- Trigger function
    CREATE OR REPLACE FUNCTION check_pointWithinPolygon()
    RETURNS trigger AS $body$
    BEGIN
    IF TG_OP = 'INSERT'
    THEN
    IF ((SELECT count(*) FROM (SELECT poly.id FROM poly WHERE st_Within(NEW.geom, poly.geom)) as foo) > 0) THEN
    RETURN NEW;
    ELSE
    RAISE EXCEPTION 'inserted feature ID:% is not within a poly', NEW.id;
    END IF;
    END IF;
    END;
    $body$ LANGUAGE plpgsql;
    COMMIT;


    -- apply the trigger function in a trigger
    CREATE TRIGGER myPointInPoly BEFORE INSERT OR UPDATE
    ON points FOR EACH ROW
    EXECUTE PROCEDURE check_pointWithinPolygon();
    COMMIT;


    All this works well. I am using QGIS to edit the layer. Some point fall within polygons ( ok) some outside ( and are caught by the trigger). The problem comes when QGIS "save edits" committs the changes.



    Currently, all edits are discarded if even a single record is not accepted. I would like to commit per row, so that those that are correct, are inserted. I am not sure whether this is something that can be caught in the trigger logic ( likely), or also needs reflection in the QGIS commit code.










    share|improve this question

























      0












      0








      0








      I have a PostGIS trigger assuring that records with a Point geometry inserted in a table fall within Polygons in another table.



      Simple example:



      -- Trigger function
      CREATE OR REPLACE FUNCTION check_pointWithinPolygon()
      RETURNS trigger AS $body$
      BEGIN
      IF TG_OP = 'INSERT'
      THEN
      IF ((SELECT count(*) FROM (SELECT poly.id FROM poly WHERE st_Within(NEW.geom, poly.geom)) as foo) > 0) THEN
      RETURN NEW;
      ELSE
      RAISE EXCEPTION 'inserted feature ID:% is not within a poly', NEW.id;
      END IF;
      END IF;
      END;
      $body$ LANGUAGE plpgsql;
      COMMIT;


      -- apply the trigger function in a trigger
      CREATE TRIGGER myPointInPoly BEFORE INSERT OR UPDATE
      ON points FOR EACH ROW
      EXECUTE PROCEDURE check_pointWithinPolygon();
      COMMIT;


      All this works well. I am using QGIS to edit the layer. Some point fall within polygons ( ok) some outside ( and are caught by the trigger). The problem comes when QGIS "save edits" committs the changes.



      Currently, all edits are discarded if even a single record is not accepted. I would like to commit per row, so that those that are correct, are inserted. I am not sure whether this is something that can be caught in the trigger logic ( likely), or also needs reflection in the QGIS commit code.










      share|improve this question














      I have a PostGIS trigger assuring that records with a Point geometry inserted in a table fall within Polygons in another table.



      Simple example:



      -- Trigger function
      CREATE OR REPLACE FUNCTION check_pointWithinPolygon()
      RETURNS trigger AS $body$
      BEGIN
      IF TG_OP = 'INSERT'
      THEN
      IF ((SELECT count(*) FROM (SELECT poly.id FROM poly WHERE st_Within(NEW.geom, poly.geom)) as foo) > 0) THEN
      RETURN NEW;
      ELSE
      RAISE EXCEPTION 'inserted feature ID:% is not within a poly', NEW.id;
      END IF;
      END IF;
      END;
      $body$ LANGUAGE plpgsql;
      COMMIT;


      -- apply the trigger function in a trigger
      CREATE TRIGGER myPointInPoly BEFORE INSERT OR UPDATE
      ON points FOR EACH ROW
      EXECUTE PROCEDURE check_pointWithinPolygon();
      COMMIT;


      All this works well. I am using QGIS to edit the layer. Some point fall within polygons ( ok) some outside ( and are caught by the trigger). The problem comes when QGIS "save edits" committs the changes.



      Currently, all edits are discarded if even a single record is not accepted. I would like to commit per row, so that those that are correct, are inserted. I am not sure whether this is something that can be caught in the trigger logic ( likely), or also needs reflection in the QGIS commit code.







      qgis postgis postgresql trigger






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 10 mins ago









      MartinTMartinT

      38919




      38919






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317861%2fper-row-commit-when-editing-postgis-data-with-qgis-with-postgis-triggers-checki%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317861%2fper-row-commit-when-editing-postgis-data-with-qgis-with-postgis-triggers-checki%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

          Meter-Bus Содержание Параметры шины | Стандартизация |...