All Forums Database
Manu3196 3 posts Joined 10/10
17 Oct 2010
Why do we need integer datatypes

Hi All,
I have a question regarding the teradata datatypes.
The question is why do we need integer datatypes when the same purpose is being served in by decimal(n,0).
I do read that there is no advantage in termes of storage space as both are stored as 2's complementay form results in occupying the same amount of space.If my understanding is wrong or if there are any other advantages kindly let me know.

Please let me know if you need any more information.
Thanks in advance
Manu

Tags:
dnoeth 4628 posts Joined 11/04
18 Oct 2010

Hi Manu,
it's better to have more choices available :-)

Differences which come to mind:
- integers are truncated, but decimals are rounded, e.g. select 2/3 vs. select 2./3.
- the range of values is larger for integers with the storage size, e.g. byteint: -128..128, dec(2,0): -99..99

Dieter

Dieter

Manu3196 3 posts Joined 10/10
18 Oct 2010

My undesrstading is even for dec(2,0) the maximum positive value that can be stored is 127 sice the decimal datatypes are stored as binary 2's complementay form and the range of values that are stored if I have a byte which is 8 bits is -2^8 to {(2^8) - 1} which means -128 to 127 (2^8 - 1).
Please correct me if my understading is wrong.

Manu3196 3 posts Joined 10/10
18 Oct 2010

I have just now verified by creating a sample table with dec(2,0) and tried to insert digits 100,110,127.
But I could not succeed.I still wonder bcz the teradata document (The one which I got along with installation) says the internal storage format is 2's complementary but practically it is not allowing me store the digits >99 and < 127.
Now I really wannna know how would be the storage of decimal datatypes in teradata.

Any help would be appreciated.

dnoeth 4628 posts Joined 11/04
18 Oct 2010

Hi Manu,
the maximum to be stored for 2 byte integer is 127, so in theory this could be stored in a dec(2,0), but 127 are 3 digits and and dec(2,0) only defines 2 digits, so 127 simply doesn't fit.

A decimal is stored as a scaled integer, i.e. a dec(4,2) is stored as "value * 100".

1..2 digits -> 1 byte
3..4 -> 2
5..9 -> 4
10..18 -> 8
19..38 -> 16

Did you happen to work with Oracle before? Those NUMBERs are quite proprietary :-)

Dieter

Dieter

You must sign in to leave a comment.