0

How can I test if a PostGIS topology with a given name exists? I don't want to run into error when creating the topology with:

SELECT topology.CreateTopology('topology_name', 1);
Sebastian Barth
  • 4,079
  • 7
  • 40
  • 59

2 Answers2

3
SELECT topology.CreateTopology('topology_name', 1)
WHERE NOT EXISTS ( 
  SELECT * FROM topology.topology WHERE name = 'topology_name' 
);

I'm assuming you have a custom spatial_ref_sys record with SRID=1 or the creation statement would fail not finding that SRID.

strk
  • 46
  • 3
0

You can try to use a conditional expression and topology.GetTopologyID, e.g.:

SELECT COALESE(topology.GetTopologyID('topology_name'), topology.CreateTopology('topology_name', 1)) AS topo_id;
Nailgun
  • 3,999
  • 4
  • 31
  • 46