[postgis-tickets] [SCM] PostGIS branch master updated. 3.2.0-651-g7a5ae3e1c

git at osgeo.org git at osgeo.org
Fri Mar 18 16:13:02 PDT 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  7a5ae3e1c3f0aee192601d4648b86d2f5717a3e5 (commit)
      from  d4bcabe852f436d17311257a0b04df71dc1d6eda (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7a5ae3e1c3f0aee192601d4648b86d2f5717a3e5
Author: Sandro Santilli <strk at kbt.io>
Date:   Fri Mar 18 21:32:36 2022 +0100

    Execute pending constraints before dropping topology
    
    References #5115 in master branch (3.3.0dev)
    Includes test

diff --git a/topology/test/regress/droptopology.sql b/topology/test/regress/droptopology.sql
index 0b63a6d71..7f12a2b34 100644
--- a/topology/test/regress/droptopology.sql
+++ b/topology/test/regress/droptopology.sql
@@ -31,6 +31,14 @@ INSERT INTO t3.f(g) VALUES (toTopoGeom('POINT(0 0)', 't3', 1));
 --SELECT topology.DropTopoGeometryColumn('t3', 'f', 'g');
 SELECT topology.DropTopology('t3');
 
+-- Test DropTopology with pending deferred triggers
+-- See https://trac.osgeo.org/postgis/ticket/5115
+BEGIN;
+SELECT 't5115.create' FROM topology.CreateTopology('t5115');
+SELECT 't5115.addline' FROM topology.TopoGeo_addLineString('t5115', 'LINESTRING(0 0, 10 0)');
+SELECT 't5115.drop' FROM topology.DropTopology('t5115');
+ROLLBACK;
+
 -- Exceptions
 SELECT topology.DropTopology('topology');
 SELECT topology.DropTopology('doesnotexist');
diff --git a/topology/test/regress/droptopology_expected b/topology/test/regress/droptopology_expected
index 37905a4d3..3c5f8570a 100644
--- a/topology/test/regress/droptopology_expected
+++ b/topology/test/regress/droptopology_expected
@@ -1,5 +1,8 @@
 Topology 't1' dropped
 Topology 't2' dropped
 Topology 't3' dropped
+t5115.create
+t5115.addline
+t5115.drop
 ERROR:  Topology 'topology' does not exist
 ERROR:  Topology 'doesnotexist' does not exist
diff --git a/topology/topology.sql.in b/topology/topology.sql.in
index 0d92c8f39..a522cbcf2 100644
--- a/topology/topology.sql.in
+++ b/topology/topology.sql.in
@@ -1704,6 +1704,8 @@ DECLARE
   topoid integer;
   rec RECORD;
   sql TEXT;
+  toposchema REGNAMESPACE;
+  deferred_constraints TEXT[];
 BEGIN
   -- Get topology id
   SELECT id INTO topoid
@@ -1744,14 +1746,37 @@ BEGIN
 #endif
 
   -- Drop the schema (if it exists)
-  FOR rec IN SELECT * FROM pg_namespace WHERE text(nspname) = atopology
-  LOOP
+  SELECT oid FROM pg_namespace WHERE text(nspname) = atopology
+  INTO toposchema;
+
+  IF toposchema IS NOT NULL THEN --{
+
+    -- Give immediate execution to pending constraints
+    -- in the topology schema.
+    --
+    -- See https://trac.osgeo.org/postgis/ticket/5115
+    SELECT array_agg(format('%I.%I', atopology, conname))
+    FROM pg_constraint c
+    WHERE connamespace = toposchema AND condeferred
+    INTO deferred_constraints;
+
+    IF deferred_constraints IS NOT NULL THEN --{
+      sql := format(
+        'SET constraints %s IMMEDIATE',
+        array_to_string(deferred_constraints, ',')
+      );
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+      RAISE DEBUG 'Executing: %', sql;
+#endif
+      EXECUTE sql;
+    END IF; --}
+
     sql := format('DROP SCHEMA %I CASCADE', atopology);
 #ifdef POSTGIS_TOPOLOGY_DEBUG
     RAISE DEBUG 'Executing: %', sql;
 #endif
     EXECUTE sql;
-  END LOOP;
+  END IF; --}
 
   RETURN format('Topology %L dropped', atopology);
 END

-----------------------------------------------------------------------

Summary of changes:
 topology/test/regress/droptopology.sql      |  8 ++++++++
 topology/test/regress/droptopology_expected |  3 +++
 topology/topology.sql.in                    | 31 ++++++++++++++++++++++++++---
 3 files changed, 39 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list