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.

  • 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, 2013 at 5:18
  • 1
    Upper or lower case in function names doesn't matter in PostgreSQL Oct 29, 2013 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, 2013 at 7:50
  • @NicklasAvén there you go didn't know that. Been using SQL Server which seems to care.
    – Nathan W
    Oct 29, 2013 at 10:01

1 Answer 1



Take a look at the doc: http://postgis.net/docs/manual-2.1/ST_Contains.html

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));
  • 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, 2013 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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