By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,779 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,779 IT Pros & Developers. It's quick & easy.

declaring variables?

P: n/a
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
Share this Question
Share on Google+
2 Replies

P: n/a
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

P: n/a
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.