470,580 Members | 2,200 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,580 developers. It's quick & easy.

declaring variables?

Is it possible to do something like this in postgres?

set variable_name = select ....
select count(*)/$variable_name ....

Basically, for a series of queries I need to do, I want to pull a count once
and reuse that count in subsequent queries to calculate percentages.

thx
andy

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #1
2 4269
You can create a temporary table to do this. Temporary tables are only
valid in the session they are created in. So,

create temporary table mytmptable(myvar whatevertype);
set variable_name = select ....
insert into mytmptable (myvar) select ....
select count(*)/$variable_name ....


select count(*) / (select myvar from mytmptable limit 1) ....

Jon
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #2
CoL
Hi,

Jonathan Bartlett wrote, On 7/2/2003 9:39 PM:
You can create a temporary table to do this. Temporary tables are only
valid in the session they are created in. So,

create temporary table mytmptable(myvar whatevertype);
set variable_name = select ....


insert into mytmptable (myvar) select ....
select count(*)/$variable_name ....


select count(*) / (select myvar from mytmptable limit 1) ....

How about:
select count(*) / (select 12) from ... ?:))

C.

Nov 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Oliver Corona | last post: by
2 posts views Thread by ross.oneill | last post: by
1 post views Thread by ColinWard | last post: by
6 posts views Thread by Mark A. Sam | last post: by
6 posts views Thread by =?Utf-8?B?QUw=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.