 -- Mailing addresses
 CREATE TABLE addresses (
     address_id serial PRIMARY KEY, -- Address identifier
-    site_id integer REFERENCES sites NOT NULL, -- Site identifier
     line1 text NOT NULL, -- Address line 1
     line2 text, -- Address line 2
     line3 text, -- Address line 3

LEFT JOIN address_types USING (address_type_id)
GROUP BY address_id;

CREATE VIEW site_addresses AS
SELECT site_id,
array_to_string(array_accum(address_id), ',') AS address_ids
FROM addresses
GROUP BY site_id;

--------------------------------------------------------------------------------

-- Each mailing address can be one of several types
CREATE TABLE address_address_type (
    address_id integer REFERENCES addresses NOT NULL, -- Address identifier
    address_type_id integer REFERENCES address_types NOT NULL, -- Address type
    PRIMARY KEY (address_id, address_type_id)
) WITH OIDS;
CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);

CREATE VIEW address_address_types AS
SELECT address_id,
