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 36C183A3D71 for ; Sun, 23 Jan 2005 11:37:53 +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 51237-05 for ; Sun, 23 Jan 2005 11:37:36 +0000 (GMT) Received: from hotmail.com (bay13-f29.bay13.hotmail.com [64.4.31.29]) by svr1.postgresql.org (Postfix) with ESMTP id 88A793A5205 for ; Sun, 23 Jan 2005 11:37:01 +0000 (GMT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sun, 23 Jan 2005 03:37:00 -0800 Message-ID: Received: from 82.233.117.145 by by13fd.bay13.hotmail.msn.com with HTTP; Sun, 23 Jan 2005 11:36:11 GMT X-Originating-IP: [82.233.117.145] X-Originating-Email: [a_eti@hotmail.com] X-Sender: a_eti@hotmail.com Reply-To: mrblonde@locked.myftp.org In-Reply-To: <20050122193539.GA88448@winnie.fuhr.org> From: "adam etienne" To: mike@fuhr.org Cc: pgsql-sql@postgresql.org Subject: Re: update from multiple rows Date: Sun, 23 Jan 2005 11:36:11 +0000 Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp; format=flowed X-OriginalArrivalTime: 23 Jan 2005 11:37:00.0936 (UTC) FILETIME=[DA716880:01C5013F] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.032 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_POST, MSGID_FROM_MTA_HEADER X-Spam-Level: * X-Archive-Number: 200501/200 X-Sequence-Number: 19988 Thanks for your answer In fact the computation is somewhat more complex than an average and the data set is quite large... I did some test with view & triggers but it's too slow.. Moreover, sometime i need to do big insertion or update and then other time i need juste little update of this table... I would like to apply a trigger only for little update but i don't know how to proceed.. Maybe with a condition into the trigger.. But it's adding computation time... Thanks again, Etienne Adam > > I have some trouble updating a table like this one : > > date | data_raw | data_sys > > 12-01 | 5 | 4.5 > > 13-01 | 6 | 6 > > 14-01 | 7 | 8 > > > > I would like to update the 'data_sys' row by computing values of multiple > > 'data_raw' values. I mean for example : > > data_sys(13-01) = (data_raw['12-01'] + data_raw['13-01'] + > > data_raw['14-01'] )/3; > >Is there a reason to maintain data_sys in the table? Could you use >a view instead? A view could do self joins (join the table against >itself) and perform the necessary calculations on the fly when you >make a query. That could be expensive if you select large data >sets, but for small slices of data it might suffice. > >Another possibility might be to use a trigger to recalculate data_sys >when records are inserted, updated, or deleted. You'd still have >to do a potentially expensive one-time update of the entire table, >but future updates would then touch only the rows that depend on >the data being inserted, updated, or deleted, and the calculated >values would always be current. Using a trigger would require some >care, however, to avoid cascading updates that are unnecessary or >that could result in infinite recursion. _________________________________________________________________ 無料メールならやっぱり 「MSN Hotmail」 http://www.hotmail.com/