Thread: POWER vs. POW ???

POWER vs. POW ???

From
Christopher Kings-Lynne
Date:
How come these give slightly different results?

test=# SELECT POW(2,-2); pow
------ 0.25
(1 row)

test=# SELECT POWER(2,-2); power
-------  0.25
(1 row)


(Note width of result field.)

Chris


Re: POWER vs. POW ???

From
Michael Glaesemann
Date:
On Nov 24, 2005, at 21:00 , Christopher Kings-Lynne wrote:

> How come these give slightly different results?
>
> test=# SELECT POW(2,-2);
>  pow
> ------
>  0.25
> (1 row)
>
> test=# SELECT POWER(2,-2);
>  power
> -------
>   0.25
> (1 row)
>
>
> (Note width of result field.)

It appears that the line is extended one underscore beyond the width  
of the wider of the attribute name and value. Am I missing something?

test=# create table foo (this_is_a_long_attribute text not null,  
short_attr text not null);
CREATE TABLE
test=# insert into foo (this_is_a_long_attribute, short_attr) values  
('narrow_value', 'this_is_a_very_wide_value');
INSERT 0 1
test=# select * from foo;
this_is_a_long_attribute |        short_attr
--------------------------+---------------------------
narrow_value             | this_is_a_very_wide_value
(1 row)

Michael Glaesemann
grzm myrealbox com





Re: POWER vs. POW ???

From
"D'Arcy J.M. Cain"
Date:
On Thu, 24 Nov 2005 20:00:21 +0800
Christopher Kings-Lynne <chriskl@familyhealth.com.au> wrote:
> How come these give slightly different results?
> 
> test=# SELECT POW(2,-2);
>   pow
> ------
>   0.25
> (1 row)
> 
> test=# SELECT POWER(2,-2);
>   power
> -------
>    0.25
> (1 row)
> 
> 
> (Note width of result field.)

The width of the label?  Note that the first is controlled by the
result.  The width of the result is four.  Add a padding space on each
end and you get six.  With the second the label (power vs. pow) is
larger than the result so it controls the width.  It is five so add a
padding space on each end and you get seven, one more than the first.
Check these out.

test=# SELECT POW(2,-2) AS REALLY_BIG_LABEL;really_big_label
------------------            0.25
(1 row)

test=# SELECT POWER(2,-2) AS X; x
------0.25
(1 row)

-- 
D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


Re: POWER vs. POW ???

From
Christopher Kings-Lynne
Date:
Also, POW() is not documented here:

http://www.postgresql.org/docs/8.1/interactive/functions-math.html

Chris

Christopher Kings-Lynne wrote:
> How come these give slightly different results?
> 
> test=# SELECT POW(2,-2);
>  pow
> ------
>  0.25
> (1 row)
> 
> test=# SELECT POWER(2,-2);
>  power
> -------
>   0.25
> (1 row)
> 
> 
> (Note width of result field.)
> 
> Chris
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>               http://archives.postgresql.org


Re: POWER vs. POW ???

From
Christopher Kings-Lynne
Date:
> It appears that the line is extended one underscore beyond the width  of 
> the wider of the attribute name and value. Am I missing something?

Ah yes, I'm stupid :P

Chris


Re: POWER vs. POW ???

From
Reinoud van Leeuwen
Date:
On Thu, Nov 24, 2005 at 08:00:21PM +0800, Christopher Kings-Lynne wrote:
> How come these give slightly different results?
> 
> test=# SELECT POW(2,-2);
>  pow
> ------
>  0.25
> (1 row)
> 
> test=# SELECT POWER(2,-2);
>  power
> -------
>   0.25
> (1 row)
> 
> 
> (Note width of result field.)

The result field is the length of min(the string, printable result) + 2:

# SELECT POW(2,-2);pow
------0.25
(1 row)

# SELECT POW(2,-2) as power;power
------- 0.25
(1 row)

# SELECT POW(2,-2) as p; p
------0.25
(1 row)

-- 
__________________________________________________
"Nothing is as subjective as reality"
Reinoud van Leeuwen    reinoud.v@n.leeuwen.net
http://www.xs4all.nl/~reinoud
__________________________________________________


Re: POWER vs. POW ???

From
Bruce Momjian
Date:
Christopher Kings-Lynne wrote:
> Also, POW() is not documented here:

I think POW is just there for backward compatibility and people should
use POWER().

---------------------------------------------------------------------------


> 
> http://www.postgresql.org/docs/8.1/interactive/functions-math.html
> 
> Chris
> 
> Christopher Kings-Lynne wrote:
> > How come these give slightly different results?
> > 
> > test=# SELECT POW(2,-2);
> >  pow
> > ------
> >  0.25
> > (1 row)
> > 
> > test=# SELECT POWER(2,-2);
> >  power
> > -------
> >   0.25
> > (1 row)
> > 
> > 
> > (Note width of result field.)
> > 
> > Chris
> > 
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Have you searched our list archives?
> > 
> >               http://archives.postgresql.org
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq
> 

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073