dbTalk Databases Forums  

Overflow on SUM of a column defined as INT

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Overflow on SUM of a column defined as INT in the comp.databases.ibm-db2 forum.



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

Default Overflow on SUM of a column defined as INT - 09-11-2010 , 02:36 AM






If a column is defined as SMALLINT, and one does a SUM (or other similar
function) on that column, the result is an INT. However, if the column is an
INT, the result of the SUM function remains an INT.

This is causing overflow on our data warehouse queries that are
automatically generated by a point and click tool (such as Cognos), and we
cannot ask end users to customize the SQL to cast the result as BIGINT,
because it is all point and click and they never see the SQL.

Any chance of getting DB2 to automatically make SUM function result into
BIGINT if the table column is INT? How do I request such an enhancement from
IBM?

Having to define the detail columns as BIGINT just because a column may be
SUM'ed will waste a lot space in our warehouse since we have billions of
rows.

Reply With Quote
  #2  
Old   
Tonkuma
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-11-2010 , 04:07 AM






One idea is to create a view using "BIGINT(int_column_name) AS
int_column_name".
Then, show the view to users.

Reply With Quote
  #3  
Old   
Luuk
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-11-2010 , 05:43 AM



Op 11-09-10 09:36, Martin schreef:
Quote:
If a column is defined as SMALLINT, and one does a SUM (or other similar
function) on that column, the result is an INT. However, if the column is an
INT, the result of the SUM function remains an INT.

This is causing overflow on our data warehouse queries that are
automatically generated by a point and click tool (such as Cognos), and we
cannot ask end users to customize the SQL to cast the result as BIGINT,
because it is all point and click and they never see the SQL.

Any chance of getting DB2 to automatically make SUM function result into
BIGINT if the table column is INT? How do I request such an enhancement from
IBM?

Having to define the detail columns as BIGINT just because a column may be
SUM'ed will waste a lot space in our warehouse since we have billions of
rows.


According to some googling, i found that DB2 functions can be overloaded

So you should be able (but i dont know how) to create your own SUM()
function that always returns a BIGINT

--
Luuk

Reply With Quote
  #4  
Old   
Luuk
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-11-2010 , 08:09 AM



Op 11-09-10 12:43, Luuk schreef:
Quote:
Op 11-09-10 09:36, Martin schreef:
If a column is defined as SMALLINT, and one does a SUM (or other similar
function) on that column, the result is an INT. However, if the column
is an
INT, the result of the SUM function remains an INT.

This is causing overflow on our data warehouse queries that are
automatically generated by a point and click tool (such as Cognos),
and we
cannot ask end users to customize the SQL to cast the result as BIGINT,
because it is all point and click and they never see the SQL.

Any chance of getting DB2 to automatically make SUM function result into
BIGINT if the table column is INT? How do I request such an
enhancement from
IBM?

Having to define the detail columns as BIGINT just because a column
may be
SUM'ed will waste a lot space in our warehouse since we have billions of
rows.



According to some googling, i found that DB2 functions can be overloaded

So you should be able (but i dont know how) to create your own SUM()
function that always returns a BIGINT

to clarify more,
there is an "How to Create User-Defined Functions" in COGNOS
(i found it at: http://apsdwh.vlaanderen.be/cognos/help/hwtcrtudfs.pdf)

i think this is a problem for COGNOS, or any reporting tool...?



--
Luuk

Reply With Quote
  #5  
Old   
Martin
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-11-2010 , 07:59 PM



"Luuk" <Luuk (AT) invalid (DOT) lan> wrote

Quote:
According to some googling, i found that DB2 functions can be overloaded

So you should be able (but i dont know how) to create your own SUM()
function that always returns a BIGINT

--
Luuk
I don't understand how a custom function is going to be used by a
point-and-click report generator.

Reply With Quote
  #6  
Old   
Martin
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-11-2010 , 08:04 PM



"Tonkuma" <tonkuma (AT) fiberbit (DOT) net> wrote

Quote:
Excellent!

I tried it and successed.

SUM( INT(edlevel) )
I don't understand how a point-and-click report writer (which only
understands standard SQL functions) is going to generate the above
expression. Maybe I am missing something.

BTW, you don't need to cast a SUM as INT, since that is the default of doing
a SUM, even if the base column is a SMALLINT. The problem is that a SUM of
INT also returns INT (instead of BIGINT).

Reply With Quote
  #7  
Old   
Tonkuma
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-11-2010 , 09:30 PM



On Sep 12, 10:04*am, "Martin" <n... (AT) none (DOT) com> wrote:
Quote:
"Tonkuma" <tonk... (AT) fiberbit (DOT) net> wrote in message

news:0facafad-9872-492c-8d62-2290a6918ccc (AT) s17g2000prh (DOT) googlegroups.com...

Excellent!

I tried it and successed.

SUM( INT(edlevel) )

I don't understand how a point-and-click report writer (which only
understands standard SQL functions) is going to generate the above
expression. Maybe I am missing something.
If current_path was "DB2ADMIN" ,
"SYSIBM","SYSFUN","SYSPROC","SYSIBMADM",
db2admin.SUM was used for SUM( INT(edlevel) ) in the query:
SELECT workdept
, SUM( INT(edlevel) ) AS educated_manpower
, SUM(salary + bonus) AS yearly_payment
FROM employee
GROUP BY
workdept
;

If current_path was SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","DB2ADMIN",
sysibm.SUM was used for SUM( INT(edlevel) ) in same query.

So, it is possible to let DB2 use db2admin.SUM instead of sysibm.SUM
without modifying queries(wheather the queries were generated by tools
or constructed by users/programmers/administrators), by updating
current_path.

Quote:
BTW, you don't need to cast a SUM as INT, since that is the default of doing
a SUM, even if the base column is a SMALLINT. The problem is that a SUM of
INT also returns INT (instead of BIGINT).
I used INT(edlevel), because I couldn't find INT column in DB2
supplied SAMPLE tables.

Reply With Quote
  #8  
Old   
Luuk
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-12-2010 , 11:20 AM



Op 12-09-10 02:59, Martin schreef:
Quote:
"Luuk"<Luuk (AT) invalid (DOT) lan> wrote in message
news:s23sl7-p6m.ln1 (AT) qqqqq (DOT) xs4all.nl...
According to some googling, i found that DB2 functions can be overloaded

So you should be able (but i dont know how) to create your own SUM()
function that always returns a BIGINT

--
Luuk

I don't understand how a custom function is going to be used by a
point-and-click report generator.


"Tonkuma" explained that in another thread....
(if you dont see it, look here: http://tinyurl.com/2w54s7x)

Basically you define a new function for the user of this report-regenerator,
give it the name SUM
and make it return a BIGINT (which contains, of course, the SUM)

--
Luuk

Reply With Quote
  #9  
Old   
Martin
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-12-2010 , 12:39 PM



"Luuk" <Luuk (AT) invalid (DOT) lan> wrote

Quote:
"Tonkuma" explained that in another thread....
(if you dont see it, look here: http://tinyurl.com/2w54s7x)

Basically you define a new function for the user of this
report-regenerator,
give it the name SUM
and make it return a BIGINT (which contains, of course, the SUM)

--
Luuk
I did the following:

1. created the new function as DB2INST1.SUM that converts SUM to BIGINT
2. db2 SET PATH = "DB2INST1","SYSIBM","SYSFUN","SYSPROC","SYSIBMADM"
3. db2 select sum(edlevel) from emp -- this returns an INT
4. db2 select db2inst1.sum(edlevel) from emp -- this returns a BIGINT

I need number 3 above to return a BIGINT. I cannot have the query tool
customize the SQL in any way.

Reply With Quote
  #10  
Old   
Tonkuma
 
Posts: n/a

Default Re: Overflow on SUM of a column defined as INT - 09-12-2010 , 02:45 PM



On Sep 13, 2:39*am, "Martin" <n... (AT) none (DOT) com> wrote:
Quote:
I did the following:

1. created the new function as DB2INST1.SUM that converts SUM to BIGINT
2. db2 SET PATH = "DB2INST1","SYSIBM","SYSFUN","SYSPROC","SYSIBMADM"
3. db2 select sum(edlevel) from emp -- this returns an INT
4. db2 select db2inst1.sum(edlevel) from emp -- this returns a BIGINT

I need number 3 above to return a BIGINT. I cannot have the query tool
customize the SQL in any way.
How did you created the table emp?
(I don't know DB2 supplied emp table.)

I guessed that data type of edlevel in emp is SMALLINT.
Another my guess was that you created the new function as
DB2INST1.SUM( INT ).
If so, best fit for sum(edlevel) in number 3 above is sysibm.sum.
Because sysibm.sum accept SMALLINT directly, while db2inst1.sum need
to convert SMALLINT to INT.

If all my guess looks appropriate, you can confirm my guess by using
sum( INT(edlevel) ) in number 3.
Or change data type of edlevel in emp to INT.

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.