#5115 closed defect (fixed)
Deferred constraint prevents dropping topology
Reported by: | ccrook | Owned by: | strk |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 3.0.6 |
Component: | topology | Version: | 3.0.x |
Keywords: | Cc: |
Description
I have a use case for creating and dropping a temporary topology in a plpgsql procedure. This fails because of the pending constraint checks. The example code is:
DO $script$ BEGIN PERFORM topology.createtopology('mytopology',4167,0.00001); PERFORM topology.topogeo_addlinestring('mytopology',ST_SetSRID( ST_MakeLine( ST_MakePoint(167.0,-45.0), ST_MakePoint(167.00001,-45.00001) ),4167)); PERFORM topology.droptopology('mytopology'); END $script$
This generates an error:
ERROR: cannot DROP TABLE "edge_data" because it has pending trigger events CONTEXT: SQL statement "DROP SCHEMA mytopology CASCADE" PL/pgSQL function droptopology(character varying) line 38 at EXECUTE SQL statement "SELECT topology.droptopology('mytopology')" PL/pgSQL function inline_code_block line 9 at PERFORM SQL state: 55006
Change History (7)
comment:1 by , 3 years ago
Status: | new → assigned |
---|
comment:3 by , 3 years ago
Milestone: | PostGIS 3.3.0 → PostGIS 3.0.6 |
---|---|
Version: | 3.2.x → 3.0.x |
I now remembered: constraints are deferred because it would otherwise be hard to construct topologies as the first edge in a ring of edges would need to reference the id of an edge which was not inserted yet… THere are probably ways to let the caller deal with deferring constraints but doing it at this time would be a behaviour change so I'd avoid to do that unless there's a very good reason.
comment:7 by , 3 years ago
Thanks Sandro. Really appreciate the extraordinarily fast fix and also providing a good workaround which has resolved this problem for me in the short term.
Issue confirmed. The issue is present also in PostGIS-3.0 (and probably earlier too). Work in progress fix is here: https://gitlab.com/postgis/postgis/-/merge_requests/73
Those pending constraints need to be executed in order for the drop to be accepted. You can force executing them with this:
Or, to be stricter:
To be honest I forgot why we're making those constraints deferred, it may have been a bad choice