jeudi 1 janvier 2015

Trigger not working in Postgres


Would some take a look at my trigger? It's not working and I don't understand why. There must be a syntax error somewhere.



CREATE OR REPLACE FUNCTION fn_parcels_compute_props() RETURNS trigger LANGUAGE plpgsql
AS $$
begin
new.lonlat := ST_Centroid(new.geometry);
new.area := ST_Area((new.geometry)::geography);
-- This value is present here in the `new` record. But that record is not
-- what is in the table after insertion. :<
RAISE NOTICE 'area is ... %', new.area;
return new;
end
$$;

CREATE TRIGGER parcels_compute_props BEFORE INSERT
ON parcels FOR EACH ROW EXECUTE PROCEDURE fn_parcels_compute_props();




Aucun commentaire:

Enregistrer un commentaire