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

From: merlyn(at)stonehenge(dot)com (Randal L(dot) Schwartz)
To: "Pat M" <pmeloy(at)removethispart(dot)home(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: My brain hurts - update field based on value of another table's field
Date: 2001-09-27 21:05:01
Message-ID: m1n13gqr9e.fsf@halfdome.holdit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>>>> "Pat" == Pat M <pmeloy(at)removethispart(dot)home(dot)com> writes:

Pat> I know I can join things together in queries, avoiding all this,
Pat> but it gets real confusing trying to join 12 tables, and
Pat> slow... I want to be able to get the area from the buildings
Pat> table and not have to join three tables just to find out what
Pat> area it belongs to. Unless someone knows an easier way than
Pat> select area_name from areas,sites,buildings where
Pat> area_id=site_area and site_id=building_id and building_id=1;
Pat> Speed and easy queries are my focus, not disk space or ram
Pat> savings.

Just build a view that wraps that part of the join, and map updates on
that view back to the consituent tables (or just forbid writes to
those tables). Then you can construct queries as if those one or two
extra columns were part of that table, and they'll never get out of sync.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn(at)stonehenge(dot)com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Benjamin Franks 2001-09-27 21:19:18 PostgreSQL 7.1 on SMP: FreeBSD 4.3 || Linux 2.4.x?
Previous Message Mihai Gheorghiu 2001-09-27 20:47:47 Successful EXECUTE