Re: Reuse temporary calculation results in an SQL update query

From: Matthias Nagel <matthias(dot)h(dot)nagel(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Reuse temporary calculation results in an SQL update query
Date: 2012-09-29 11:04:23
Message-ID: 1687060.cmZrQAXiMV@hek506
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

> Matthias Nagel <matthias(dot)h(dot)nagel(at)gmail(dot)com> 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(dot)h(dot)nagel(at)gmail(dot)com
ICQ: 499797758
Skype: nagmat84

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jasen Betts 2012-09-29 11:20:04 Re: Reuse temporary calculation results in an SQL update query
Previous Message Andreas Kretschmer 2012-09-29 10:56:35 Re: Reuse temporary calculation results in an SQL update query