[postgis-users] PostGIS Trigger doesn't work

Ralf Suhr Ralf.Suhr at itc-halle.de
Mon Jan 28 09:29:59 PST 2013


Hi Marcello,

your trigger is fired before any data is in table "adutoras". 

CREATE OR REPLACE FUNCTION topology_fields()
RETURNS trigger AS
$$
BEGIN

  SELECT string_agg(municipios.nome,', ')
  INTO NEW.municipios_abastecidos
  FROM municipios
  WHERE ST_Intersects(NEW.geom, municipios.geom);

  RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
   

Gr
Ralf

On Montag 28 Januar 2013 16:11:35 Marcello Benigno wrote:
   Hello All,
   
   The trigger below don't works and I need that when a new pipeline
   (adutoras) is inserted or updated, the procedure check what are the
   municipalities (municipios) that intersects the pipes and put the names of
   the municipalities inside the field "municipios_abastecidos".
   
   CREATE OR REPLACE FUNCTION topology_fields()
   RETURNS "trigger" AS$$BEGIN
   NEW.municipios_abastecidos:=(
                         SELECT string_agg(municipios.nome,', ')
                         FROM municipios, adutoras
                         WHERE ST_Intersects(adutoras.geom, municipios.geom)
                         AND adutoras.gid = NEW.gid
                       );RETURN NEW;END; $$
   LANGUAGE 'plpgsql';
   
   CREATE TRIGGER fill_topology_fields
   BEFORE INSERT OR UPDATE ON adutorasFOR EACH ROW EXECUTE PROCEDURE
   topology_fields();
   
   
   Thanks in advance,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20130128/6855d82a/attachment.html>


More information about the postgis-users mailing list