pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
AVG function
4+ messages / 3 participants
[nested] [flat]

* AVG function
@ 1999-08-28 15:09 rodneyr@embratel.com.br
  1999-08-28 15:48 ` Re: [INTERFACES] AVG function Hannu Krosing <hannu@trust.ee>
  0 siblings, 1 reply; 4+ messages in thread

From: rodneyr@embratel.com.br @ 1999-08-28 15:09 UTC (permalink / raw)
  To: pgsql-interfaces@hub.org

I'm using the AVG function to get the average of some integer values of my
database,
but the result is comming in the integer format too, and I'm loosing some
precision.

Does someone know how to get the result of the AVG function in a float type,
without
changing the structure of my table?

Thanks,

Rodney.





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [INTERFACES] AVG function
  1999-08-28 15:09 AVG function rodneyr@embratel.com.br
@ 1999-08-28 15:48 ` Hannu Krosing <hannu@trust.ee>
  1999-08-28 18:16   ` Re: [INTERFACES] AVG function Billy G. Allie <Bill.Allie@mug.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Hannu Krosing @ 1999-08-28 15:48 UTC (permalink / raw)
  To: rodneyr@embratel.com.br; +Cc: pgsql-interfaces@hub.org

rodneyr@embratel.com.br wrote:
> 
> I'm using the AVG function to get the average of some integer values of my
> database,
> but the result is comming in the integer format too, and I'm loosing some
> precision.
> 
> Does someone know how to get the result of the AVG function in a float type,
> without
> changing the structure of my table?

Try this:

hannu=> select * from t;
i
-
4
4
4
4
3
(5 rows)
 
hannu=> select avg(i * 1.0) from t;
avg
---
3.8
(1 row)


-------------
Hannu



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [INTERFACES] AVG function
  1999-08-28 15:09 AVG function rodneyr@embratel.com.br
  1999-08-28 15:48 ` Re: [INTERFACES] AVG function Hannu Krosing <hannu@trust.ee>
@ 1999-08-28 18:16   ` Billy G. Allie <Bill.Allie@mug.org>
  1999-08-28 20:54     ` Re: [INTERFACES] AVG function Hannu Krosing <hannu@trust.ee>
  0 siblings, 1 reply; 4+ messages in thread

From: Billy G. Allie @ 1999-08-28 18:16 UTC (permalink / raw)
  To: Hannu Krosing <hannu@trust.ee>; +Cc: rodneyr@embratel.com.br; pgsql-interfaces@hub.org; bga@mug.org

Hannu Krosing wrote:
> rodneyr@embratel.com.br wrote:
> > 
> > I'm using the AVG function to get the average of some integer values of my
> > database,
> > but the result is comming in the integer format too, and I'm loosing some
> > precision.
> > 
> > Does someone know how to get the result of the AVG function in a float type,
> > without
> > changing the structure of my table?
> 
> Try this:
> 
> hannu=> select * from t;
> i
> -
> 4
> 4
> 4
> 4
> 3
> (5 rows)
>  
> hannu=> select avg(i * 1.0) from t;
> avg
> ---
> 3.8
> (1 row)
> 
Actually, this will work without the need for a multiplication:

	bga=> select * from t;
	i
	-
	1
	2
	3
	4
	5
	6
	(6 rows)

	bga=> select AVG(i::float) from t;
	avg
	---
	3.5
	(1 row)

-- 
____       | Billy G. Allie    | Domain....: Bill.Allie@mug.org
|  /|      | 7436 Hartwell     | Compuserve: 76337,2061
|-/-|----- | Dearborn, MI 48126| MSN.......: B_G_Allie@email.msn.com
|/  |LLIE  | (313) 582-1540    | 

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [INTERFACES] AVG function
  1999-08-28 15:09 AVG function rodneyr@embratel.com.br
  1999-08-28 15:48 ` Re: [INTERFACES] AVG function Hannu Krosing <hannu@trust.ee>
  1999-08-28 18:16   ` Re: [INTERFACES] AVG function Billy G. Allie <Bill.Allie@mug.org>
@ 1999-08-28 20:54     ` Hannu Krosing <hannu@trust.ee>
  0 siblings, 0 replies; 4+ messages in thread

From: Hannu Krosing @ 1999-08-28 20:54 UTC (permalink / raw)
  To: Billy G. Allie <Bill.Allie@mug.org>; +Cc: rodneyr@embratel.com.br; pgsql-interfaces@hub.org; bga@mug.org

"Billy G. Allie" wrote:
> 
> Hannu Krosing wrote:
> > rodneyr@embratel.com.br wrote:
> >
> > > Does someone know how to get the result of the AVG function in a float type,
> > > without changing the structure of my table?
> >
> > Try this:
> >
> > hannu=> select avg(i * 1.0) from t;
> > avg
> > ---
> > 3.8
> > (1 row)
> >
> Actually, this will work without the need for a multiplication:
> 
>         bga=> select AVG(i::float) from t;
>         avg
>         ---
>         3.5
>         (1 row)

The ANSI-fied form of which is :

hannu=> select avg(cast(i as float)) from t;
avg
---
3.8
(1 row)

---------------
Hannu



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~1999-08-28 20:54 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-08-28 15:09 AVG function rodneyr@embratel.com.br
1999-08-28 15:48 ` Hannu Krosing <hannu@trust.ee>
1999-08-28 18:16   ` Billy G. Allie <Bill.Allie@mug.org>
1999-08-28 20:54     ` Hannu Krosing <hannu@trust.ee>

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