Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 27 Mar 2002 @ 15:25:46 GMT


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


Subj:   Re: A question on Casting
 
From:   Geoffrey Rommel

  I have a very simple question on casting, should the following return the same result or no, if yes - why? And if not - why?  


   select 1(char); /* Implicit Cast */
   select cast(1 as char); /* Explicit Cast */

Should they? Well, probably they should, but they don't.

(Side note: Actually, both of these are explicit casts. The following would result in an implicit cast:

insert into hey_jude ( char_column )
  select  numeric_column from nowhere_man;)

The difference is that the first is a Teradata cast, the second an ANSI cast. In your Teradata cast, you are getting only the first character of the result, which happens to be a blank. Consider the following results.

select 1(char(20));  /* Teradata version */

1
--------------------
   1

select cast(1 as char(20));  /* ANSI */

1
--------------------
1

I don't know why ANSI is defined the way it is, but I think I can explain the Teradata version. The literal 1 is implicitly defined as the smallest data type it will fit in, namely BYTEINT. Since BYTEINTs can range from -128 to +127, the default format for them is '---9', and so casting them to character will always require at least 4 bytes.



     
  <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