[GIS] PostGIS Type Modifier Error

geocodingpostgispostgresqlpython

I'm trying to work an example from the "PostGIS Cookbook" and I'm getting an error I don't understand. I'm running the example using Postgres.app on a MacBook. Postgres.app is running PostgreSQL 9.1.12 with PostGIS 1.5.3.

Here's the PL/Python function:

-- load.sql
CREATE OR REPLACE FUNCTION Geocode(address text)
    RETURNS geometry(Point, 4326)
AS $$
    from geopy import geocoders
    g = geocoders.GoogleV3()
    place, (lat, lng) = g.geocode(address)
    plpy.info('Geocoded %s for the address: %s' % (place, address))
    plpy.info('Longitude is %s, Latitude is %s.' % (lng, lat))
    plpy.info("SELECT ST_GeomFromText('POINT(%s %s)', 4326)" % (lng, lat))
    result = plpy.execute("SELECT ST_GeomFromText('POINT(%s %s)', 4326) AS point_geocded" % (lng, lat))
    geometry = result[0]["point_geocoded"]
    return geometry
$$ LANGUAGE plpythonu;

When I try to load the function into the database with this command:

psql geodjango < load.sql

I get this error:

ERROR: type modifier is not allowed for type "geometry"

I suspect this error has something to do with the fact that the book example assumes you're using PostGIS 2.0 and I'm using 1.5.3. However, it still doesn't make sense to me. I'm read about the ST_GeomFromText function in the PostGIS 1.5 Manual and this code appears to be correct. What am I doing wrong?

Thanks.

Best Answer

Just change the second line

RETURNS geometry(Point, 4326)

to

RETURNS geometry

The "type modifier" is a 2.0 feature. You might have other problems if GeoAlchemy expects PostGIS 2.0+, but for this particular function, just removing the typmod syntax should suffice.