Opened 9 years ago

Closed 9 years ago

#1235 closed defect (invalid)

cast to unknown-srid typmod fails

Reported by: strk Owned by: pramsey
Priority: medium Milestone: PostGIS 2.0.0
Component: postgis Version: master
Keywords: Cc:

Description

This brief session seems inconsistent to me:

strk=# select st_srid(geom::geometry('multipolygon', 0)) from poly;
 st_srid
---------
    4326
(1 row)

strk=# select st_srid(geom::geometry('multipolygon', 2)) from poly;
ERROR:  Geometry SRID (4326) does not match column SRID (2)

Basically the first cast attempt silently fails (the returned geometry has still the original srid, rather than the one I requested: 0).

Change History (4)

comment:1 Changed 9 years ago by strk

Summary: cast to different-srid typmodcast to unknown-srid typmod fails

comment:2 Changed 9 years ago by robe

strk -- is this a geography table you are casting to geometry?

I'm not sure I consider this a bug (except it is the unknown srid), but remember unknonwn is the same as not specifying an srid at all so I would expect it to maintain the same srid.

I would think the proper way to do this is:

ST_SetSRID(geom:geometry,0)::geometry('multipolygon',0);

The reason I think that is that there are two ways you can cast -- you can cast by doing a transform or set the srid explicitly. I don't think we should be making assumptions about how people want the translation to happen.

For example if you had a linestring and tried to do this

geom::geometry(LINESTRING)

That would be illegal.

comment:3 Changed 9 years ago by robe

For clarification:

Recall we said that not specifying an srid (or using the unknonw one 0) is the same as allowing any srids?

So what you have should in theory be the same as

SELECT geom:geometry('multipolygon');

That would keep the same srid as it had before -- namely 4326 in this case.

comment:4 Changed 9 years ago by strk

Resolution: invalid
Status: newclosed

Alright, I'm convinced. The cast doesn't and shouldn't set the srid.

Note: See TracTickets for help on using tickets.