There's more...

While we have a function created, we have not yet applied it as a trigger to the table. Let us do that here as follows:

CREATE TRIGGER popgeom_insert  BEFORE INSERT ON chp02.xwhyzed1  FOR EACH ROW EXECUTE PROCEDURE chp02.before_insertXYZ();

Let's assume that the general geometry column update has not taken place yet, then the original five registers still have their geometry column in null. Now, once the trigger has been activated, any inserts into our table should be populated with new geometry records. Let us do a test insert using the following query:

INSERT INTO chp02.xwhyzed1 (x, y, z)  VALUES (random()*5, random()*7, 106),  (random()*5, random()*7, 107),  (random()*5, random()*7, 108),  (random()*5, random()*7, 109), (random()*5, ...

Get PostGIS Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.