dbTalk Databases Forums  

[BUGS] BUG #1762: Integer multiplication error

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


Discuss [BUGS] BUG #1762: Integer multiplication error in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Milos Babic
 
Posts: n/a

Default [BUGS] BUG #1762: Integer multiplication error - 07-09-2005 , 06:05 AM







The following bug has been logged online:

Bug reference: 1762
Logged by: Milos Babic
Email address: milos.babic (AT) gmail (DOT) com
PostgreSQL version: 8.0
Operating system: FreeBSD
Description: Integer multiplication error
Details:

When I try from psql to select:

select 1024*1024*4500;

it responses with:
error integer out of range

is it known bug or what is going on?

almost, even worst thing happens on postgresql version 7.4.2 on SuSe Linux
9.1
when I try
select 1024*1024*4500;

it responses with
423624704
!!!

it also happens when I try to insert 1024*1024*4500 into int8 field in
database!

Best regards
milos

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply With Quote
  #2  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] BUG #1762: Integer multiplication error - 07-09-2005 , 08:31 AM






On Sat, Jul 09, 2005 at 10:25:16AM +0100, Milos Babic wrote:
Quote:
When I try from psql to select:

select 1024*1024*4500;

it responses with:
error integer out of range

is it known bug or what is going on?
From "Numeric Constants" in the "SQL Syntax" chapter of the
documentation:

A numeric constant that contains neither a decimal point nor an
exponent is initially presumed to be type integer if its value
fits in type integer (32 bits); otherwise it is presumed to be
type bigint if its value fits in type bigint (64 bits); otherwise
it is taken to be type numeric.

All three constants in the expression meet the criteria for being
an integer, so the expression's result will be an integer as well.
Since the result (4718592000) would overflow 32 bits, PostgreSQL
raises an error (versions prior to 8.0 gave an incorrect result,
as you discovered).

Quote:
it also happens when I try to insert 1024*1024*4500 into int8 field in
database!
The expression has to be evaluated before it can be inserted into
a table, and since it's an integer expression you get the overflow
error. Cast one of the operands to bigint if you want the result
to be a bigint.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


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.