Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 814F6475CB2 for ; Mon, 3 Jun 2002 08:03:36 -0400 (EDT) Received: from server.beierfeld.kabeljournal.de (pD9508747.dip.t-dialin.net [217.80.135.71]) by postgresql.org (Postfix) with SMTP id 4EAAC475F73 for ; Mon, 3 Jun 2002 07:55:12 -0400 (EDT) Received: (qmail 4177 invoked from network); 3 Jun 2002 07:55:11 -0000 Received: from station158.beierfeld.kabeljournal.de (HELO station158) (192.168.128.158) by server.beierfeld.kabeljournal.de with SMTP; 3 Jun 2002 07:55:11 -0000 Date: Mon, 3 Jun 2002 10:00:28 +0200 From: Andre Schubert To: pgsql-sql@postgresql.org Subject: How to update Message-Id: <20020603100028.38dd8a7e.andre.schubert@km3.de> Organization: km3 teledienst GmbH X-Mailer: Sylpheed version 0.7.5 (GTK+ 1.2.6; i586-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200206/12 X-Sequence-Number: 7977 Hi all, i have a simple problem with an sql-update. Lets say i have a table foo which contains a ip::inet and to counters inet and local. And i have a table bar which contains ip::inet inet and local. I need these two tables for traffic-accounting. The table foo should contain the sum of traffic of bar, therefore once a month i would like to run a script which performs a query that selects sum(inet),sum(local) from bar and updates foo with these two values where bar.ip = foo.ip. Who can explain how to perform this action with one query. I tried this, but it update always one row in foo. update foo set inet=sum(bar.inet),local=sum(bar.local) where foo.ip = bar.ip; Thanks in advance P.S.: Sorry for my bad english, hope you understand what i mean :)