Opened 15 years ago

Last modified 15 years ago

#269 closed defect

Geometry -> Geography autocast should be explicit — at Version 3

Reported by: mcayland Owned by: pramsey
Priority: medium Milestone: PostGIS 1.5.0
Component: postgis Version:
Keywords: Cc:

Description (last modified by robe)

Changed subject:

We really shouldn't be allowing people to use functions designated for geometry with geography data type without forcing them to explicitly cast to geometry.


This is bad:

trunk=# explain analyze select count(*) from cities where the_geog && ST_SetSRID(ST_GeographyFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'), 4326);

ERROR: operator is not unique: geography && geometry LINE 1: ...nalyze select count(*) from cities where the_geog && ST_SetS...

Change History (3)

comment:1 by robe, 15 years ago

Resolution: invalid
Status: newclosed

Mark, I consider this bug invalid and not a bug. I don't personally see this as an issue because how would it know -- If people exercise this it will be

geography && unknown

geometry && unknown

In which case the operation is not ambiguous. In your case you are clearly doing a

geometry && geography which is a big no no in my book. And you should be slapped on the wrist for even attempting such a silly thing :)

for example the below works perfectly fine.

SELECT name
FROM neighborhoods 
WHERE geography(ST_Transform(the_geom,4326)) && 'POINT(-71.0155762507496 42.3724551968706)'

comment:2 by mcayland, 15 years ago

Oh - I totally agree that geometry && geography is a no-no, but the error message being returned is effectively a developer's error saying "Don't do that". Abusing the implicit cast system in this way to enable things to get this far is just plain wrong, and will cause confusion to users as to exactly which functions have been tested in a geography context and which haven't. With the cast removed, I get the following message which is a lot more sensible:

trunk=# explain analyze select count(*) from cities where the_geog && ST_SetSRID(ST_GeographyFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'), 4326);

ERROR: function st_setsrid(geography, integer) does not exist

I'd like to propose that we remove the implict cast and replace it with an explicit cast instead. Then if users want to try functions that haven't been tested with geography, then at least they will be made aware they are trying something non-standard and can face the relevant consequences.

comment:3 by robe, 15 years ago

Description: modified (diff)
Resolution: invalid
Status: closedreopened
Summary: Geometry -> Geography autocast causes && operator query to failGeometry -> Geography autocast should be explicit

Ah okay that's what you are complaining about. I'm in full agreement with you on this one then. I'm going to change the subject line to be clearer and reopen the ticket.

Note: See TracTickets for help on using tickets.