I try to avoid wheel reuse when it comes to storing street addresses in a table only once. Uniqueness constraints will not work in some common situations:
100 W 5th Ave 100 West 5th Ave 100 W 5th 200 N 6th Ave Suite 405 200 N 6th Ave
I could implement some business logic or a trigger to normalize all fields before inserting and using uniqueness constraints for several fields in a table, but it would be easy to miss some cases with something that varies the same way as street addresses.
What would be best would be a universal identifier for each address, possibly based on GPS coordinates. Before saving the new address, find your GUID and see if the GUID exists in the Address table.
An organization such as Mapquest, Postal Serice, FedEx, or the US government probably has such a system.
Has anyone found a good solution for this?
Now my address table (generated by JPA):
CREATE TABLE address ( id bigint NOT NULL, "number" character varying(255), dir character varying(255), street character varying(255), "type" character varying(255), trailingdir character varying(255), unit character varying(255), city character varying(255), state character varying(255), zip integer, zip4 integer, CONSTRAINT address_pkey PRIMARY KEY (id) )
source share