casting bigint to varchar issue

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
Enthusiast

casting bigint to varchar issue

Hi Team,

 

When i try to convert BIGINT to VARCHAR, I get a dot at the end. Can you please let me know if there is a reason for it ?

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 905 StartFragment: 314 EndFragment: 873 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

select cast(123909949494999494 as varchar(200)) --> 123909949494999494.

 Thanks,

Sundar


Accepted Solutions
Apprentice

Re: casting bigint to varchar issue

When you supply a numeric integer literal without specifying a data type, Teradata will normally fit it into the smallest integer (byteint, smallint, integer) data type that can hold the value.

 

It seems that once you go over 10 digits then it uses DECIMAL data type (probably until you go over 38 digits).Your case creates a DECIMAL(18,0).

 

Cheers,

Dave

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com
1 ACCEPTED SOLUTION
4 REPLIES
Apprentice

Re: casting bigint to varchar issue

Hi,

 

Your value is not treated as a BIGINT, it is treated as DECIMAL(18,0) and the default FORMAT for decimal data types with 0 digits after the decimal point has a '.' at the end.

 

Cheers,

Dave

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com
Enthusiast

Re: casting bigint to varchar issue

Thanks Dave for the explanation. Is there a reason why the value is treated as DECIMAL & not as a Bigint ?

 

Thanks,

Sundar

Apprentice

Re: casting bigint to varchar issue

When you supply a numeric integer literal without specifying a data type, Teradata will normally fit it into the smallest integer (byteint, smallint, integer) data type that can hold the value.

 

It seems that once you go over 10 digits then it uses DECIMAL data type (probably until you go over 38 digits).Your case creates a DECIMAL(18,0).

 

Cheers,

Dave

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com
Enthusiast

Re: casting bigint to varchar issue

Thank you for answering this patiently and helping me understand the working ! :)