X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 959A0D1E0E9 for ; Thu, 19 Feb 2004 03:11:07 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 92992-06 for ; Wed, 18 Feb 2004 23:11:08 -0400 (AST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id DFB67D1E0DB for ; Wed, 18 Feb 2004 23:11:04 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 90C72357B2; Wed, 18 Feb 2004 19:11:08 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 8F4D135568; Wed, 18 Feb 2004 19:11:08 -0800 (PST) Date: Wed, 18 Feb 2004 19:11:08 -0800 (PST) From: Stephan Szabo To: Sean Shanny Cc: pgsql-sql@postgresql.org Subject: Re: Need some help with crafting a query to do major update In-Reply-To: <4034087C.6090606@earthlink.net> Message-ID: <20040218190832.H38717@megazone.bigpanda.com> References: <4034087C.6090606@earthlink.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/267 X-Sequence-Number: 16957 On Wed, 18 Feb 2004, Sean Shanny wrote: > To all, > > This is part of a data warehouse. Made the mistake of using a natural > key in one of the fact tables. :-( The f_test_pageviews is a simple > testing table while I work this out. The real table has an identical > schema. > > I have built a mapping table, d_user, to allow the replacement of the > text based (32 characters wide) subscriber_key in f_test_pageviews with > an int4 mapping key. I need to replace all of the > f_test_pageviews.subscriber_key values with the d_user.id value putting > it in f_test_pageviews.sub_key column. > > I have tried this sql: > > update f_test_pageviews set sub_key = t2.id from f_test_pageviews t1, > d_user t2 where t1.subscriber_key = t2.user_id; I don't think the above does what you want because I don't think you meant to be joining f_test_pageviews in twice (once as the table to be updated and once as t1) or at least not without limiting which rows you want to update. I think you probably just want: update f_test_pageviews set sub_key=t2.id from d_user t2 where f_test_pageviews.subscriber_key=t2.user_id;