Re: My brain hurts - update field based on value of another table's field

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: My brain hurts - update field based on value of another table's field
Date: 2001-09-23 22:23:05
Message-ID: 9olnc8$8sv$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> * area - arbitrary name for a collection of sites (optional)
>
> * site name for a collection of buildings (may only be one building)
> optional
>
> * building - a single building not optional name for a collection of rooms
>
> * zone - sub area of a building not optional name for a collection of rooms.
>
> * rooms (not listed)
>

CREATE TABLE room (room_id int, room_name text);
CREATE TABLE zone (zone_id int, zone_name text);
CREATE TABLE zone_room (zone_id int REFERENCES zone,
room_id int REFERENCES room);
CREATE TABLE building (building_id int, building_name text);
CREATE TABLE building_zone (building_id int REFERENCES building,
zone_id int REFERENCES zone);
CREATE TABLE site (site_id int, site_name text);
CREATE TABLE site_building (site_id int REFERENCES site,
building_id int REFERENCES building);
CREATE TABLE area (area_id int, area_name text);
CREATE TABLE area_site (area_id int REFERENCES area,
site_id int REFERENCES site);

I think I would do something like this. Try not to duplicate information
anywhere in your schema. This way, if you decide to move a site to a
different area or a room to a different building ;) you only need to
change it in one place.

>
> The main record here is Building. Areas and sites are optional ways of
> grouping buildings. Zones and rooms are required.
>
> Since the area and site are optional and arbitrary (you may change your
> organizational chart) I need a way of updating the children of that record
> to reflect the changes. I can do it easy enough in php, just don't know how
> with postgres.
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message R Talbot 2001-09-23 22:26:35 Re: Where are Perl DBI and DBD for PostgreSQL??
Previous Message Marinos J. Yannikos 2001-09-23 22:17:23 Re: How to make a REALLY FAST db server?