Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Using ST_Contains in where clause sometimes gives me error messages like

ERROR: GEOSContains: TopologyException: side location conflict at 37.3706 55.7882

For now I can't guarantee validity for every geometry in DB, using third-party import tools, so I just catch every exception:

CREATE OR REPLACE FUNCTION safe_st_contains(geom1 geometry, geom2 geometry)
    RETURN ST_Contains($1, $2);
      RAISE NOTICE 'TopologyException'; -- this is a guess
LANGUAGE plpgsql;

I'd like to know where exceptions like TopologyException really belong and which exception conditions should I use instead of OTHERS ?

share|improve this question

2 Answers 2

Best I could find by briefly looking at the PostGIS code was, that these kind of exceptions are raised by GEOS. So I would recommend you to look at their wiki, sources etc. like

share|improve this answer
Here's how you can search the source for "TopologyException" – Mike T Aug 31 '14 at 21:35

Assuming you can reproduce the error, you can get the exact error code yourself pretty easily:

DO $$
    PERFORM ST_Contains('problem 1 geom here'::GEOMETRY, 'problem geom 2 here'::GEOMETRY);
      RAISE NOTICE 'Error code: %', SQLSTATE;
      RAISE NOTICE 'Error message: %', SQLERRM;

(Put your actual geometries in, of course.)

Running this will print out the code and the error message.

I wasn't doing ST_Contains, but as an example, I got this result from a particular TopologyException I'm running into:

Error code: XX000
Error message: GEOSUnaryUnion: TopologyException: found non-noded intersection between LINESTRING (401336 4.79544e+06, 401336 4.79544e+06) and LINESTRING (401336 4.79544e+06, 401339 4.79543e+06) at 401336.24785627011 4795435.9978510197

The PostgreSQL error codes list says that XX000 is "internal_error". My best guess is that this is just the code PostgreSQL uses when random, third party native code blows up, since PostgreSQL can't do all that much with those errors. Might be worth getting on the PostGIS mailing list and seeing if they can do something to at least give general PostGIS errors a more specific code.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.