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

Поиск
Список
Период
Сортировка
От merlyn@stonehenge.com (Randal L. Schwartz)
Тема Re: My brain hurts - update field based on value of another table's field
Дата
Msg-id m1n13gqr9e.fsf@halfdome.holdit.com
обсуждение исходный текст
Ответ на My brain hurts - update field based on value of another table's field  ("Pat M" <pmeloy@removethispart.home.com>)
Список pgsql-general
>>>>> "Pat" == Pat M <pmeloy@removethispart.home.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@stonehenge.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!

В списке pgsql-general по дате отправления:

Предыдущее
От: Doug McNaught
Дата:
Сообщение: Re: what is wrong with this SQL?
Следующее
От: Doug McNaught
Дата:
Сообщение: Re: what is wrong with this SQL?