X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9B1D73AC366 for ; Wed, 15 Dec 2004 10:07:52 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19998-06 for ; Wed, 15 Dec 2004 10:07:42 +0000 (GMT) Received: from smiley.hyperbyte.ab.ca (unknown [216.123.213.196]) by svr1.postgresql.org (Postfix) with ESMTP id 0ACB73AC329 for ; Wed, 15 Dec 2004 10:07:40 +0000 (GMT) Received: from hyperbyte.ab.ca (S0106000d88ba03d1.cg.shawcable.net [68.144.50.151]) by smiley.hyperbyte.ab.ca (Postfix) with ESMTP id 7DD5EFF848 for ; Wed, 15 Dec 2004 03:08:41 -0700 (MST) Date: Wed, 15 Dec 2004 03:07:03 -0700 Mime-Version: 1.0 (Apple Message framework v553) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: Updating column to link one table to another From: Mark Collette To: pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit Message-Id: <114A1D38-4E81-11D9-BAA1-0050E4799418@hyperbyte.ab.ca> X-Mailer: Apple Mail (2.553) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200412/131 X-Sequence-Number: 19751 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