Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1THuqV-0005IT-0Q for pgsql-sql@postgresql.org; Sat, 29 Sep 2012 11:04:31 +0000 Received: from mail-bk0-f46.google.com ([209.85.214.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1THuqR-0007Ix-3T for pgsql-sql@postgresql.org; Sat, 29 Sep 2012 11:04:29 +0000 Received: by bkcjk13 with SMTP id jk13so4071367bkc.19 for ; Sat, 29 Sep 2012 04:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:content-type; bh=mU2XO/jHXSul+gA2/T9kRRJQUrbmSvsbYBgVWzExkK0=; b=xsbtxDt9PdVPMBa1MokuDIl64ZBzK1e3bmM22xr9fxeTVcv/Uu+oafWzu7Wx4VXqc1 RxyeP+pXV+HnvPC6MipFsGLGLXVtmUeS2eb75bUjnIXn/Yu5fS2BCuyMpqhn6FV1YHp1 13ukrniX2/8wRAm18EDKRu7m7E31m2WsnoiSBVjTK38j0gSZv2r5dAD/6tY6EXQSQq4Y m/OvSe0ey3TLANZv8bqvLw34Y3oJcVyrXrXzVuN0W4s5rcO4ap+1pARjE8DWIpZzGNxb utwiNITCiX9bqSq2scmVtKweJlmxfGKcgCnjAF9COP11PhcTxNPNhN01FV+THx0QjSbC 8pRg== Received: by 10.204.9.130 with SMTP id l2mr4549722bkl.56.1348916665747; Sat, 29 Sep 2012 04:04:25 -0700 (PDT) Received: from hek506.localnet ([2001:7c0:409:274:213:77ff:febe:8a56]) by mx.google.com with ESMTPS id e13sm3473535bkw.12.2012.09.29.04.04.24 (version=SSLv3 cipher=OTHER); Sat, 29 Sep 2012 04:04:25 -0700 (PDT) From: Matthias Nagel To: pgsql-sql@postgresql.org Subject: Re: Reuse temporary calculation results in an SQL update query Date: Sat, 29 Sep 2012 13:04:23 +0200 Message-ID: <1687060.cmZrQAXiMV@hek506> User-Agent: KMail/4.8.3 (Linux/3.4.9-gentoo; KDE/4.8.3; x86_64; ; ) In-Reply-To: <1237868969.148407.1348916195838.JavaMail.open-xchange@ox.ims-firmen.de> References: <43516431.HfO3TYfNBy@hek506> <1237868969.148407.1348916195838.JavaMail.open-xchange@ox.ims-firmen.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201209/59 X-Sequence-Number: 36861 Hello, > Matthias Nagel hat am 29. September 2012 um 12:49 > geschrieben: > > Hello, > > > > is there any way how one can store the result of a time-consuming calculation > > if this result is needed more than once in an SQL update query? This solution > > might be PostgreSQL specific and not standard SQL compliant. Here is an > > example of what I want: > > > > UPDATE table1 SET > > StartTime = 'time consuming calculation 1', > > StopTime = 'time consuming calculation 2', > > Duration = 'time consuming calculation 2' - 'time consuming calculation 1' > > WHERE foo; > > The Duration - field is superfluous ... > I expected the answer ;-), but no, it is not superfluous. In this small example it might appear as if it is, but there are cases in that the start time and the duration time have values and the stop time equals null to indicate a running session. And for reasons that are beyond the orginal question, there are also cases where duration does not equal the difference between start and stop time. > As far as i know there is no way to re-use the result. Too bad. > Regards, Andreas Thanks, Matthias ---------------------------------------------------------------------- Matthias Nagel Willy-Andreas-Allee 1, Zimmer 506 76131 Karlsruhe Telefon: +49-721-8695-1506 Mobil: +49-151-15998774 e-Mail: matthias.h.nagel@gmail.com ICQ: 499797758 Skype: nagmat84