pg.ddx.io pgsql-general@postgresql.org mailing list archivehelp / color / mirror / Atom feed
"storing" a calculated value in plsql function ? 3+ messages / 3 participants [nested] [flat]
* "storing" a calculated value in plsql function ? @ 2019-08-30 10:48 stan <stanb@panix.com> 2019-08-30 11:08 ` Re: "storing" a calculated value in plsql function ? Luca Ferrari <fluca1978@gmail.com> 2019-08-30 12:21 ` Re: "storing" a calculated value in plsql function ? Pavel Stehule <pavel.stehule@gmail.com> 0 siblings, 2 replies; 3+ messages in thread From: stan @ 2019-08-30 10:48 UTC (permalink / raw) To: pgsql-general@lists.postgresql.org I have created a function (PLSQL) that does a complex select with joins on various tables and views, and returns a table. 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 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? -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: "storing" a calculated value in plsql function ? 2019-08-30 10:48 "storing" a calculated value in plsql function ? stan <stanb@panix.com> @ 2019-08-30 11:08 ` Luca Ferrari <fluca1978@gmail.com> 1 sibling, 0 replies; 3+ messages in thread From: Luca Ferrari @ 2019-08-30 11:08 UTC (permalink / raw) To: stan <stanb@panix.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org> On Fri, Aug 30, 2019 at 12:48 PM stan <stanb@panix.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_Listing...;. Luca ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: "storing" a calculated value in plsql function ? 2019-08-30 10:48 "storing" a calculated value in plsql function ? stan <stanb@panix.com> @ 2019-08-30 12:21 ` Pavel Stehule <pavel.stehule@gmail.com> 1 sibling, 0 replies; 3+ messages in thread From: Pavel Stehule @ 2019-08-30 12:21 UTC (permalink / raw) To: stan <stanb@panix.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org> pá 30. 8. 2019 v 12:48 odesílatel stan <stanb@panix.com> napsal: > I have created a function (PLSQL) that does a complex select with joins on > various > tables and views, and returns a table. > > 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 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? > you can use custom configuration values like global variables https://wiki.postgresql.org/wiki/Variable_Design#PostgreSQL_User-Defined_GUCS Regards Pavel Stehule > > -- > "They that would give up essential liberty for temporary safety deserve > neither liberty nor safety." > -- Benjamin Franklin > > > ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2019-08-30 12:21 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-08-30 10:48 "storing" a calculated value in plsql function ? stan <stanb@panix.com> 2019-08-30 11:08 ` Luca Ferrari <fluca1978@gmail.com> 2019-08-30 12:21 ` Pavel Stehule <pavel.stehule@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox