Search code examples
sqlpostgistopology

Check if a PostGIS topology with a given name exists


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);

Solution

  • 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.