From: Mark Collette <mark@hyperbyte.ab.ca>
To: pgsql-sql@postgresql.org
Subject: Updating column to link one table to another
Date: Wed, 15 Dec 2004 03:07:03 -0700
Message-ID: <114A1D38-4E81-11D9-BAA1-0050E4799418@hyperbyte.ab.ca> (raw)
I have two tables, with a many to one relationship.
Table InfrequentTable
- timestamp ts
- int infrequentId (newly added key)
Table FrequentTable (Many FrequentTable entries per one
InfrequentTable entry)
- timestamp ts
- int infrequentId (newly added column)
The link is chronological, in that when an InfrequentTable entry
happens, then subsequent FrequentTable entries should be linked to it,
until the next InfrequentTable event happens, in which case old
FrequentTable entries are left alone, but new ones are linked to the
newest InfrequentTable entry.
Now, I've added the infrequentId columns to both, as an optimization,
so that I can quickly find the InfrequentTable entry for a given
FrequentTable entry. I've done this because I want to speed up
SELECTs. Any new INSERTs are working just fine. But, all my legacy
entries, are not linked up yet. I need to know how I can UPDATE the
FrequentTable rows, where their infrequentId is zero, to point at the
last InfrequentTable entry whose timestamp ts is before its own
timestamp ts.
Can anyone help me with this? Thank you.
- Mark Collette
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: mark@hyperbyte.ab.ca
Subject: Re: Updating column to link one table to another
In-Reply-To: <114A1D38-4E81-11D9-BAA1-0050E4799418@hyperbyte.ab.ca>
References: <114A1D38-4E81-11D9-BAA1-0050E4799418@hyperbyte.ab.ca>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox