Re: "storing" a calculated value in plsql function ?

From: Luca Ferrari <fluca1978(at)gmail(dot)com>
To: stan <stanb(at)panix(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: "storing" a calculated value in plsql function ?
Date: 2019-08-30 11:08:42
Message-ID: CAKoxK+4sZxmk_zaqbpd-901=ysfRaBURYUKsfHcXu5wVTZHTVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Aug 30, 2019 at 12:48 PM stan <stanb(at)panix(dot)com> wrote:
> In the resultant table, I have raw data, and adjusted data. The adjusted data i
> all adjusted by a common factor, which is calculated in the select. Presently, I
> calculate this same adjustment factor several times in the select.

Is it possible to add the computed column as output of your query?
Even define a rowtype that includes such column?

> Is there a way to reference this value, multiple times, once it is calculated? Or
> would I have to create a 2nd select that calculates this adjustment factor, and
> stores it in a PLSQL variable< and if I do that, can I reference this stored value
> in the select?

Yes, you can references variables as values on queries.
As an example <https://github.com/fluca1978/PostgreSQL-11-Quick-Start-Guide/blob/master/Chapter03/Chapter03_Listing09.sql>.

Luca

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Niels Jespersen 2019-08-30 11:27:06 SSPI auth and mixed case usernames
Previous Message stan 2019-08-30 10:48:01 "storing" a calculated value in plsql function ?