Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 05 Oct 2004 @ 05:15:25 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Calculating average age per transaction
 
From:   Dennis Calkins

On Mon, 4 Oct 2004 10:04:51 -0400, TeradataForum Fred Easey wrote:

          sum(current_date - a.date_of_birth year(4))/count(*) as average_age

  When I run this I get the following error message:  


          ERROR: Teradata row not delivered (trget): Interval field overflow.

  If I take the sum out...:  


          current_date - a.date_of_birth year(4) as age

  ... then the script runs fine and I get a list of ages. Presumably summing years and dividing by count(*) is the issue, how can I fix this?  



Hi,

YEAR(4) means a MAXIMUM of 4 DIGITS (9999) in the answer. 4 Digits is the MAXIMUM allowed by ANSI SQL.

It works when you subtract the 2 dates because no SINGLE transaction is over 10000 years old.

However when you SUM the intervals, the cumlative SUM is >= 10000 years and therefore you get the overflow.

Why are you doing the SUM and COUNT(*) yourself and Not the Average Function?

I get Overflow when using SUM and Count(*), but if I use AVERAGE I don't. I think this is because Average implicitly converts the interval to a FLOAT when doing the average.

Also why are using a.date_of_Birth, when you are comparing b.date_of_Birth is not NULL. Just wondering.

I had to use MONTH(4) because none of the table where old enough to overflow YEAR(4) but the principle is the same.

      BTEQ -- Enter your DBC/SQL request or BTEQ command:
     sel sum(current_timestamp - LastAlterTimeStamp Month(4))
     from tvfields;

     sel sum(current_timestamp - LastAlterTimeStamp Month(4))
     from tvfields;
      *** Failure 7453 Interval field overflow.
                     Statement# 1, Info =0
      *** Total elapsed time was 1 second.

     sel Average(current_timestamp - LastAlterTimeStamp Month(4)),count(*)
     from tvfields;

      *** Query completed. One row found. 2 columns returned.
      *** Total elapsed time was 1 second.

     Average((Current TimeStamp(6) - LastAlterTimeStamp) MONTH)     Count(*)
     ----------------------------------------------------------  -----------
                                                              3         4257

See 4257 * 3 is greater than 10000 which is why the SUM over flows.



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023