I have the following table defined, which uses PostGIS geography.

CREATE TABLE test_geog (
    boundary GEOGRAPHY(Polygon)

I added the following test polygon to the table:

INSERT INTO test_geog VALUES (ST_GeographyFromText('SRID=4326;POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'));

I am trying to determine whether a point lies within any of the polygons in this table. I have this query:

SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'), area)
FROM (SELECT boundary FROM test_geog) AS area;

This yields the following error:

ERROR:  function st_containsproperly(geography, record) does not exist
LINE 1: SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'...
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

How do I convert this "record" into a POLYGON? I'm confused because it seems like the column has already been declared to only hold POLYGON types, but for some reason that is not what I am pulling out of the database.

I attempted to cast the record to a POLYGON like this:

SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'), CAST (nitf_area AS POLYGON))
FROM (SELECT boundary FROM source_imagery) AS nitf_area;

But that gives me this error:

ERROR:  cannot cast type record to polygon
LINE 1: ...tainsProperly(ST_GeographyFromText('Point(2 2)'), CAST (nitf...

What am I not understanding here?

1 Answer 1


Do you need the sub-select? And I think ST_ContainsProperly only works with Geometry, not Geography.

SELECT ST_ContainsProperly(
          Geometry(ST_GeographyFromText('Point(2 2)')), 
FROM test_geog;
  • Ah, yes you are right about all of that. ST_ContainsProperly only works for Geometry, so I switched to using ST_Covers instead, which does what I want. I wanted to avoid casting to Geometry if it's not necessary. Here is the code I ended up with that works: SELECT ST_Covers(boundary, ST_GeographyFromText('Point(2 2)')) FROM source_imagery
    – Steph
    Jun 22, 2011 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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