Database Reference
In-Depth Information
use.Thefirstpartofthetriggerisanewlypopulatedgeometryfunctionusingthefol-
lowing query:
CREATE OR REPLACE FUNCTION chp02.xyz_pop_geom()
RETURNS TRIGGER AS $popgeom$
BEGIN
IF(TG_OP='INSERT') THEN
UPDATE chp02.xwhyzed1
SET geom = ST_SetSRID(ST_MakePoint(x,y),
3734)
WHERE geom IS NULL
;
END IF;
RETURN NEW;
END;
$popgeom$ LANGUAGE plpgsql;
In essence, we have created a function that does exactly what we did manually:
it updates the table's geometry column with the combination of ST_SetSRID and
ST_MakePoint . The one exception here is that we've added a WHERE clause that
allowsustoapplythisonlytorowsthathavenogeometrypopulated.Thisistheper-
formant choice.
There's more...
Whilewehaveafunctioncreated,wehavenotyetapplieditasatriggertothetable.
Let us do that here as follows:
CREATE TRIGGER popgeom_insert
AFTER INSERT ON chp02.xwhyzed1
FOR EACH STATEMENT EXECUTE PROCEDURE
chp02.xyz_pop_geom();
Search WWH ::




Custom Search