[postgis-users] constraint issue in 2.0.2 r10789

Nicolas Ribot nicolas.ribot at gmail.com
Mon Dec 17 07:36:17 PST 2012


Hi,

If data contain both LINESTRING and MULTILINESTRING, then you should use
the MULTILINESTRING constraint. (this is the default shp2pgsql behavior, as
you noted).

Concerning the trigger, this is a 2 step operation:
First you create the function the trigger will call
Then you create a trigger on a table using this function:

-- function definition
create or replace function forceMulti() returns trigger as $$
    DECLARE

    BEGIN
        NEW.geom := st_multi(NEW.geom);
        RETURN NEW;
    END;
$$ LANGUAGE PLPGSQL;

-- then trigger creation
create trigger forceMulti_trigger
    BEFORE UPDATE OR INSERT
    ON profiles_line_wgs84
    FOR EACH ROW
EXECUTE PROCEDURE forceMulti();

insert into profiles_line_wgs84 (geom)
values ('srid=4326;LINESTRING(0 0, 1 1)'::geometry);

select st_astext(geom) from profiles_line_wgs84;

Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20121217/fc16107f/attachment.html>


More information about the postgis-users mailing list