<html><body><div><div><span>Uhmm... Thanks.</span></div><br><div><span>So there's no way to avoid hanging QGIS while the trigger function(s) is running. I am guessing that if I have another trigger function in a table that is automatically populated by the first trigger, it will also be executed in the QGIS transaction, right?</span></div><br><div><span>Thanks Again,</span></div><br><div><span>Alexandre Neto</span></div></div><br><div class="shortwave-signature"><div>
 Sent with <a href="https://www.shortwave.com?utm_medium=email&utm_content=signature&utm_source=c2VuaG9yLm5ldG9AZ21haWwuY29t" target="_blank" rel="noopener" style="color:#4C8AFF">Shortwave</a>
</div></div><br><div><div>On Thu Jan 4, 2024, 11:45 AM GMT, <a href="mailto:nicolas.ribot@gmail.com">Nicolas Ribot</a> wrote:<br></div><blockquote style="margin:0 0 0 4pt;padding-left:4pt;border-left:1px solid #CCC"><div><div dir="ltr">Hello,<div><br></div><div>A trigger is executed in a single transaction: "<span style="color:rgb(0,0,0);font-family:"Open Sans",sans-serif;font-size:14.4px">The execution of an </span><code class="gmail-literal" style="box-sizing:border-box;font-family:monospace,monospace;font-size:14.4px;color:rgb(0,0,0);border-radius:0.25rem;margin:0.6rem 0">AFTER</code><span style="color:rgb(0,0,0);font-family:"Open Sans",sans-serif;font-size:14.4px"> trigger can be deferred to the end of the transaction, rather than the end of the statement, if it was defined as a </span><em class="gmail-firstterm" style="box-sizing:border-box;color:rgb(0,0,0);font-family:"Open Sans",sans-serif;font-size:14.4px">constraint trigger</em><span style="color:rgb(0,0,0);font-family:"Open Sans",sans-serif;font-size:14.4px">. In all cases, a trigger is executed as part of the same transaction as the statement that triggered it, so if either the statement or the trigger causes an error, the effects of both will be rolled back.</span>" (<a href="https://www.postgresql.org/docs/16/trigger-definition.html" target="_blank" rel="noopener noreferrer">https://www.postgresql.org/docs/16/trigger-definition.html</a>)</div><div><br></div><div>So QGIS has to wait for it to finish.</div><div><br></div><div>Nicolas</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 4 Jan 2024 at 11:16, Alexandre Neto via postgis-users <<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><div><span>Sorry for the cross posting.</span></div><br><div><span>I have a table with the following trigger</span></div><br><div><b><span>CREATE</span></b><span> </span><b><span>TRIGGER</span></b><span> tr_base_cont_trocos_ai </span><b><span>AFTER</span></b></div><div><b><span>INSERT</span></b><span> </span><b><span>OR</span></b><span> </span><b><span>UPDATE</span></b><span> </span><b><span>ON</span></b><span> base.cont_troco</span></div><div><b><span>FOR</span></b><span> </span><b><span>EACH</span></b><span> </span><b><span>STATEMENT</span></b></div><div><b><span>EXECUTE</span></b><span> </span><b><span>FUNCTION</span></b><span> tr_gerar_outputs();</span></div><br><div><span>Now, the tr_gerar_outputs() takes some time to process, as it generates new tables and updates a few materialized views.</span></div><br><div><span>In QGIS, when I add or update one or more features and press save, I would expect it to be immediate, but it seems that QGIS hangs waiting for the function to finish before considering the save operation complete. If the function fails, it even prevent the feature to be commit.</span></div><br><div><span>Is this expected for a AFTER INSERT OR UPDATE trigger? Shouldn't PostgreSQL commit the changes, inform QGIS that the operation was successful and only then execute the trigger?</span></div><br><div><span>Thanks,</span></div><br><div><span>Alexandre Neto</span></div></div><br><div><div>
 Sent with <a href="https://www.shortwave.com?utm_medium=email&utm_content=signature&utm_source=c2VuaG9yLm5ldG9AZ21haWwuY29t" style="color:rgb(76,138,255)" target="_blank" rel="noopener noreferrer">Shortwave</a>
</div></div></div>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><br>
</blockquote></div>
</div></blockquote></div></body></html>