northrivergeo / tn_ng911_data_model

This is the postgresql version of the TN NG911 Standard. I'm using it with one county in TN. It's open for all to use.
GNU General Public License v2.0
0 stars 2 forks source link

Setting SegID for the centerlines #14

Closed northrivergeo closed 2 years ago

northrivergeo commented 2 years ago

In the centerline dataset there are 3 fields that Autoincrement (of sorts).

OIRID is referenced by the state and can't change for the 3 layers (address, esn, centerline). That is built by taking the ID field and adding "Henry_" to it. So you have 'Henry_1', 'Henry_2' etc.

Segid doesn't increment or do anything It needs to. We can do this one of two ways.

If we calculate it off the ID with an update trigger more or less it's something like:


CREATE OR REPLACE FUNCTION centerlines_segid() RETURNS TRIGGER AS ' BEGIN NEW.segid := new.id; RETURN NEW; END; ' language 'plpgsql';

CREATE TRIGGER update_centerlines_segid before insert on tn911.centerlines FOR EACH ROW EXECUTE PROCEDURE centerlines_segid();


I added this code to the create_vector_functions.sql script. It's not been tested.

KSnyderCode commented 2 years ago

Sounds great. I can test out later.

I'm separating out the trigger functions by table into separate scripts just for easier code:

northrivergeo commented 2 years ago

Cool - feel free to make it make more sense....because.......blargh.

northrivergeo commented 2 years ago

So I've got that working now. The segid mimics the primary key (which also provides for the OIRID) - no one said it couldn't work that way - BUT - if it nerds to be changed it can.