Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1THubu-0000Eb-NT for pgsql-sql@postgresql.org; Sat, 29 Sep 2012 10:49:27 +0000 Received: from mail-bk0-f46.google.com ([209.85.214.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1THubr-0006zC-Lb for pgsql-sql@postgresql.org; Sat, 29 Sep 2012 10:49:25 +0000 Received: by bkcjk13 with SMTP id jk13so4066993bkc.19 for ; Sat, 29 Sep 2012 03:49:22 -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:mime-version :content-transfer-encoding:content-type; bh=bBVExoW9QHPb1ig+dBh8sGnLkoNc211xUQvDOxf9F8E=; b=06cvI1tGBR6ABx2O97MnB/GU5916hZfUN0qdnZVltagAWikoGPzoK41QpENyx0yont Orp+GK9NU7qM7avO1y2pkHg7F8owI9jafmvh4VbxHWlAEh/wRzvll6deCbg+HPTTMRMH 1HNlQSnEUZ5YxmTASf96J4W8BjPbUN8vZlvembvwOukNCpzNN8OroICFmvui9CI6BfKi WUbD1gNPhHuIrgDzHlCzb5fTZR51dysYTG9XJUbUN7ANxtzfs/BrH5hF1l60z0lDlmAx /WV3c4hd4YPLvzs+DpLUaAfQp+FovCLhCpZYuSwy0EPwvq1NIL7hHt7jO9ifM13gyXDk +4zQ== Received: by 10.205.125.134 with SMTP id gs6mr2807594bkc.17.1348915761864; Sat, 29 Sep 2012 03:49:21 -0700 (PDT) Received: from hek506.localnet ([2001:7c0:409:274:213:77ff:febe:8a56]) by mx.google.com with ESMTPS id j24sm7802085bkv.0.2012.09.29.03.49.20 (version=SSLv3 cipher=OTHER); Sat, 29 Sep 2012 03:49:21 -0700 (PDT) From: Matthias Nagel To: pgsql-sql@postgresql.org Subject: Reuse temporary calculation results in an SQL update query Date: Sat, 29 Sep 2012 12:49:18 +0200 Message-ID: <43516431.HfO3TYfNBy@hek506> User-Agent: KMail/4.8.3 (Linux/3.4.9-gentoo; KDE/4.8.3; x86_64; ; ) 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/57 X-Sequence-Number: 36859 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; It would be nice, if I could use the "new" start and stop time to calculate the duration time. First of all it would make the SQL statement faster and secondly much more cleaner and easily to understand. Best regards, 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