dbTalk Databases Forums  

[BUGS] Select (str)::FLOAT8 BUG

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] Select (str)::FLOAT8 BUG in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rafael Villalobos Prats
 
Posts: n/a

Default [BUGS] Select (str)::FLOAT8 BUG - 02-18-2004 , 09:26 AM






Hi!,

I think i have found a bug.

I=B4ve tried it in PgSQL 7.3.5 & 7.4.1

When I do:

atisae_oct_1=3D# SELECT (1000/500/7)::FLOAT8 as v_numero;
v_numero
----------
0
(1 row)

atisae_oct_1=3D# SELECT 1000/500/7::FLOAT8 as v_numero;
v_numero
-------------------
0.285714285714286
(1 row)

atisae_oct_1=3D# SELECT (1000/500/7)::NUMERIC as v_numero;
v_numero
----------
0
(1 row)

atisae_oct_1=3D# SELECT 1000/500/7::NUMERIC as v_numero;
v_numero
------------------------
0.28571428571428571429
(1 row)


Why is different: 'SELECT (xxxxx)::FLOAT8' than 'SELECT xxxxx::FLOAT8'

Thanks in advance...

Rafa.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Reply With Quote
  #2  
Old   
Fothergill, Iain
 
Posts: n/a

Default Re: [BUGS] Select (str)::FLOAT8 BUG - 02-18-2004 , 09:36 AM






My guess would be...=20

1000/5000/7::FLOAT8 is really 1000::INT/500::INT/7::FLOAT8 (int may be some=
other integer type) whereas (1000/500/7)::FLOAT8 is (1000::INT/500::INT/7:=
:INT)::FLOAT8 i.e. the resultan integer is casted to type FLOAT8 after the =
maths has been done on integers. Thats what I'd expect.


Iain


Quote:
-----Original Message-----
From: pgsql-bugs-owner (AT) postgresql (DOT) org
[mailtogsql-bugs-owner (AT) postgresql (DOT) org]On Behalf Of Rafael Villalobos
Prats
Sent: Wednesday, February 18, 2004 3:38 PM
To: pgsql-bugs (AT) postgresql (DOT) org
Subject: [BUGS] Select (str)::FLOAT8 BUG
=20
=20
Hi!,
=20
I think i have found a bug.
=20
I=B4ve tried it in PgSQL 7.3.5 & 7.4.1
=20
When I do:
=20
atisae_oct_1=3D# SELECT (1000/500/7)::FLOAT8 as v_numero;
v_numero
----------
0
(1 row)
=20
atisae_oct_1=3D# SELECT 1000/500/7::FLOAT8 as v_numero;
v_numero
-------------------
0.285714285714286
(1 row)
=20
atisae_oct_1=3D# SELECT (1000/500/7)::NUMERIC as v_numero;
v_numero
----------
0
(1 row)
=20
atisae_oct_1=3D# SELECT 1000/500/7::NUMERIC as v_numero;
v_numero
------------------------
0.28571428571428571429
(1 row)
=20
=20
Why is different: 'SELECT (xxxxx)::FLOAT8' than 'SELECT xxxxx::FLOAT8'
=20
Thanks in advance...
=20
Rafa.
=20
---------------------------(end of=20
broadcast)---------------------------
TIP 6: Have you searched our list archives?
=20
http://archives.postgresql.org
=20
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Select (str)::FLOAT8 BUG - 02-18-2004 , 10:39 AM



"Rafael Villalobos Prats" <rvillalobos (AT) asapci (DOT) es> writes:
Quote:
Why is different: 'SELECT (xxxxx)::FLOAT8' than 'SELECT xxxxx::FLOAT8'
The :: operator binds more tightly than most other operators. As Iain
replied, most of your divisions are going to be integer divisions that
discard the fractional part. You can either add casts or add ".0" to
your numbers to cause them to be considered non-integers.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #4  
Old   
Tarhon-Onu Victor
 
Posts: n/a

Default Re: [BUGS] Select (str)::FLOAT8 BUG - 06-04-2004 , 12:39 AM



On Wed, 18 Feb 2004, Rafael Villalobos Prats wrote:

Quote:
I think i have found a bug.

I´ve tried it in PgSQL 7.3.5 & 7.4.1

When I do:

atisae_oct_1=# SELECT (1000/500/7)::FLOAT8 as v_numero;
v_numero
----------
0
(1 row)
This is not a bug and it also has nothing to do with postgresql.
Try the same in C and you will have the same result.
The expression 1000/500/7 contains operations between variables
of an integer type: 1000/500 = 2, 2/7=0. 0::float=0.
Probably a more accurate result will be obtained if you modify
this to:
1000::float/500/7.
In this case 1000/500/7::float or 1000::float/500/7 will return
the same result, but 1000::float/501/7 and 1000/501/7::float will not
because the first operation will be between variables of an integer
type.

--
Tarhon-Onu Victor
Area Technical Coordinator
RDS Iasi - Network Operations Center
www.rdsnet.ro, www.rdstel.ro, www.rdslink.ro
Phone: +40-232-218385; Fax: +40-232-260099
.................................................. .........................
Privileged/Confidential Information may be contained in this message. If
you are not the addressee indicated in this message (or responsible for
delivery of the message to such person), you may not copy or deliver this
message to anyone. In such a case, you should destroy this message and
kindly notify the sender by reply e-mail.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.