[postgis-devel] [PostGIS] #1320: typmod geometry type not changing in before trigger

PostGIS trac at osgeo.org
Tue Nov 22 16:45:11 PST 2011


#1320: typmod geometry type not changing in before trigger
----------------------+-----------------------------------------------------
 Reporter:  robe      |       Owner:  jomarlla@…         
     Type:  defect    |      Status:  new                
 Priority:  critical  |   Milestone:  PostGIS 2.0.0      
Component:  postgis   |     Version:  trunk              
 Keywords:            |  
----------------------+-----------------------------------------------------

Comment(by robe):

 Paul,

 Sorry I've been testing two things.  One is a bonafied bug in PostGIS
 because it works fine for geography.  I got my tests a bit mixed up.  The
 other is another demonstration of a use case that typmod doesn't work for.

 So here is the geography equivalent and it does as expected.


 {{{
 CREATE TABLE b(gid serial primary key, geog geography(MultiPolygon,
 4326));
 CREATE OR REPLACE FUNCTION public.trigb() RETURNS trigger AS
 $$
 BEGIN
 NEW.geog = ST_GeometryN(New.geog::geometry,1)::geography;
 RETURN NEW;
 END;
 $$ language plpgsql
 VOLATILE;


 CREATE TRIGGER trigb_before
   BEFORE INSERT
   ON public.b
   FOR EACH ROW
   EXECUTE PROCEDURE public.trigb();

 INSERT INTO b(geog) VALUES('MULTIPOLYGON (((0 0, 10 0, 10 10, 0
 0)))'::geography);
 }}}

 throws this error -- which is the right thing to do:


 {{{
 ERROR:  Geometry type (Polygon) does not match column type (MultiPolygon)
 CONTEXT:  PL/pgSQL function "trigb" line 2 at assignment

 }}}

 geometry typmod seems to be missing this secondary check.  The other issue
 which I think is the one bothering the poster is something there by
 design.  I'll test with varchar on that to confirm and that is that
 PostgreSQL does a signature check to make sure what you are trying to
 stuff in a table can go there before it even gets to the trigger.

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/1320#comment:2>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-devel mailing list