Search Postgresql Archives

Re: query variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 27, 2005 at 07:29:24PM -0600, j0rd1 adame wrote:

> Is there any way to save the result of a query in a variable, so that i could 
> use that value in another query??
> 
> something like set VARIABLENAME = select count(1) from table;
> and then
> select 56778/VARIABLENAME as final_result;

You could do it in a PL/pgSQL function or a function written in
another procedural language.  Another way would be to use a temporary
table:

CREATE TEMPORARY TABLE tmp AS SELECT count(*) AS foocount FROM foo;
SELECT 56778 / (SELECT foocount FROM tmp) AS final_result;

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux