How I can get the real data type result instead of integer data type?

Started by Weiabout 20 years ago6 messagesgeneral
Jump to latest
#1Wei
wei725@lycos.com

In a query, there is something like

order by count(id)/age

where both id and age are the integer data type.

From a query result, I believe the operation count(id)/age yields a integer. I need it in real data type. After searching the online document, I haven't found any related information. Can someone help me out on this problem, please.

Thanks,

w

--
_______________________________________________

Search for businesses by name, location, or phone number. -Lycos Yellow Pages

http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10

In reply to: Wei (#1)
Re: How I can get the real data type result instead of

On Mon, 2006-03-20 at 21:10, Wei Wei wrote:

In a query, there is something like

order by count(id)/age

where both id and age are the integer data type.

From a query result, I believe the operation count(id)/age yields a integer. I need it in real data type. After searching the online document, I haven't found any related information. Can someone help me out on this problem, please.

Thanks,

w

Try:

order by count(id)/age::float

regards,
Sig.Gunn

#3Bruno Wolff III
bruno@wolff.to
In reply to: Wei (#1)
Re: How I can get the real data type result instead of integer data type?

On Mon, Mar 20, 2006 at 13:10:51 -0800,
Wei Wei <wei725@lycos.com> wrote:

In a query, there is something like

order by count(id)/age

where both id and age are the integer data type.

From a query result, I believe the operation count(id)/age yields a integer. I need it in real data type. After searching the online document, I haven't found any related information. Can someone help me out on this problem, please.

You can cast the expressions. Something like:
order by count(id)::float/age::float

#4William ZHANG
uniware@zedware.org
In reply to: Wei (#1)
Re: How I can get the real data type result instead of

"Sigurdur Gunnlaugsson" <sig@fjolnet.net>

On Mon, 2006-03-20 at 21:10, Wei Wei wrote:

Try:

order by count(id)/age::float

Or you can use the standard grammer:

order by cast(count(id)/age as float)

Regards,
William ZHANG

#5Bruno Wolff III
bruno@wolff.to
In reply to: William ZHANG (#4)
Re: How I can get the real data type result instead of

On Tue, Mar 21, 2006 at 21:16:03 +0800,
William ZHANG <uniware@zedware.org> wrote:

"Sigurdur Gunnlaugsson" <sig@fjolnet.net>

On Mon, 2006-03-20 at 21:10, Wei Wei wrote:

Try:

order by count(id)/age::float

Or you can use the standard grammer:

order by cast(count(id)/age as float)

Don't you have to cast before the divide? I think the above will convert
the truncated result to float.
However he could do something like:
order by count(id)/cast(age as float)

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruno Wolff III (#5)
Re: How I can get the real data type result instead of

Bruno Wolff III <bruno@wolff.to> writes:

Try:
order by count(id)/age::float

Or you can use the standard grammer:

order by cast(count(id)/age as float)

Don't you have to cast before the divide?

Yeah. The :: case is OK because :: binds more tightly than /
but the second suggestion is wrong :-(

regards, tom lane