MSCEWI2051
Teradata BYTES function results differs from Snowflake LENGTH function for byte columns

Severity

Low

Description

Since Teradata byte datatype has a fixed length, BYTES function will always count the trailing zeros inserted to fit smaller byte type values into the column, returning the size of the column instead of the size of the value inserted originally. However, Snowflake binary type has variable size, meaning that the LENGTH function will always return the size of the inserted values. Take the following code as an example:
Teradata:
1
create table exampleTable(
2
bytecol byte(10)
3
);
4
5
insert into exampleTable values ('2B'XB);
6
7
select bytes(bytecol) from exampleTable;
8
-- Will return 10, the size of bytecol
Copied!
Equivalent code in Snowflake:
1
create table exampleTable(
2
bytecol binary
3
);
4
5
insert into exampleTable values (to_binary('2B'));
6
7
select length(bytecol) from exampleTable;
8
// Will return 1, the size of the value 2B
Copied!

Example code:

Input code:

1
create table sampleTable(
2
byteColumn byte(10),
3
varbyteColumn varbyte(15)
4
);
5
6
select bytes(byteColumn), bytes(varbyteColumn) from sampleTable;
Copied!

Output code:

1
CREATE TABLE PUBLIC.sampleTable (
2
byteColumn BINARY,
3
varbyteColumn BINARY
4
);
5
6
SELECT
7
LENGTH(byteColumn) /*** MSC-WARNING - MSCEWI2051 - TERADATA BYTES FUNCTION RESULTS DIFFER FROM SNOWFLAKE LENGTH FUNCTION FOR BYTE TYPE COLUMNS ***/,
8
LENGTH(varbyteColumn)
9
FROM PUBLIC.sampleTable
Copied!

Recommendations

    Analyze the use given to the BYTES function results, maybe the Snowflake LENGTH function behavior was the one desired from the start and no changes are required.
    For more support, you can email us at [email protected] or post a message to our forums. If you have a contract for support with Mobilize.Net, reach out to your sales engineer and they can direct your support needs.
Last modified 1mo ago