populating a field automatically

From: Larry Holish <ljholish(at)speakeasy(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: populating a field automatically
Date: 2001-02-27 19:13:08
Message-ID: 20010227131308.A1897@badlands.philberts.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello all,

I am trying to populate a field in a table by looking up values from
another table. Here are my (simplified tables):

CREATE TABLE small(
id char(14),
addr int4,
street char(15),
city char(15),
other text,
infor text,
mation text
);

CREATE TABLE big(
id char(14),
addr int4,
street char(15),
city char(15),
other text,
stuff text
);

I am trying to populate id in table small by looking up the
corresponding addr, street and city in table big. I am trying to
avoid a JOIN because table big is very large, and table small will not
change once it is constructed (lookups only). If I populate id into
table small, I can then use a simple, fast query on table small
directly.

My question is, then, how to popluate id in table small without
running each query by hand and inserting the result myself. Should I
try to use an insert trigger? I see that pl/pgsql can loop over all
the rows of a table. Is this kind of a function the way to go? Any
thoughts or suggestions would be appreciated.

--
Larry Holish
<ljholish(at)speakeasy(dot)net>

Browse pgsql-novice by date

  From Date Subject
Next Message Hector Diaz 2001-02-27 19:33:40 Re: text field size
Previous Message Tom Lane 2001-02-27 18:50:23 Re: Permissions