Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running the below query and try to identify the end point of a line with gid 338 on the polygon's boundary with gid 1456 but got some error message:

SELECT public.st_contains((Select public.st_EndPoint(the_geom) from lines where gid=338),(select public.st_Boundary(the_geom) from polygons where gid=1456))

The error message:

> ERROR:  function _st_contains(public.geometry, public.geometry) does
> not exist LINE 1: SELECT $1 && $2 AND _ST_Contains($1,$2)
> HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
> QUERY:  SELECT $1 && $2 AND _ST_Contains($1,$2) CONTEXT:  SQL function
> "st_contains" during inlining

If I run

SELECT ST_Contains(ST_GeomFromText('LINESTRING(0 0, 5 5, 10 10)'),ST_GeomFromText('point(3 3)'));

It will return "t" as the correct value.

share|improve this question
The function is ST_Contains(), you can't call it using lower case letters e.g. st_contains as far as I know. – Nathan W Oct 29 '13 at 5:18
Upper or lower case in function names doesn't matter in PostgreSQL – Nicklas Avén Oct 29 '13 at 7:03
I solved the problem by using select _st_contains(...) instead of select st_contains(...). According to the manual " This function call will automatically include a bounding box comparison that will make use of any indexes that are available on the geometries. To avoid index use, use the function _ST_Contains." – Xianlin Oct 29 '13 at 7:50
@NicklasAvén there you go didn't know that. Been using SQL Server which seems to care. – Nathan W Oct 29 '13 at 10:01
up vote 4 down vote accepted


Take a look at the doc:

Sorry, I misread your question first.

Interesting that it didn't work with your first syntax but with _st_contains().

But the way you do it is not the way you usually do it in SQL.

Your query will run with indexes if you rewrite to something like:

SELECT public.st_contains(st_EndPoint(lines.the_geom), st_Boundary(polygons.the_geom))
FROM lines, polygons 
WHERE lines.gid=338 and polygons.gid=1456;

May I guess that what you want is tho find all cases where the lines endpoints is on the boundary of a polygon. That you do with something like:

SELECT lines.gid, polygon.gid 
FROM lines INNER JOIN polygons 
ON ST_Contains(st_EndPoint(lines.the_geom), ST_Bounadary(polygons.the_geom));
share|improve this answer
I used your new format with "inner join" and I am able to find those lines endpoints is on the boundary of a polygon. Thanks! – Xianlin Oct 30 '13 at 2:26

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.