Cast from Number Datatypes to Varchar Datatype

Translation specification for the transformation of cast Varchar Datatype Snowflake.

Teradata when casts to varchar uses default formats for each number datatype, so Snowconvert adds formats to keep the equivalence among platforms.

Sample Source Patterns

BYTEINT

Teradata

IN -> Teradata_01.sql
SELECT '"'||cast(cast(12 as BYTEINT) as varchar(10))||'"';

Snowflake

OUT -> Teradata_01.sql
SELECT
'"'|| LEFT(TO_VARCHAR(cast(12 as BYTEINT), 'TM'), 10) ||'"';

SMALLINT

Teradata

IN -> Teradata_02.sql
SELECT '"'||cast(cast(123 as SMALLINT) as varchar(10))||'"';

Snowflake

OUT -> Teradata_02.sql
SELECT
'"'|| LEFT(TO_VARCHAR(CAST(123 AS SMALLINT), 'TM'), 10) ||'"';

INTEGER

Teradata

IN -> Teradata_03.sql
SELECT '"'||cast(cast(12345 as INTEGER) as varchar(10))||'"';

Snowflake

OUT -> Teradata_03.sql
SELECT
'"'|| LEFT(TO_VARCHAR(CAST(12345 AS INTEGER), 'TM'), 10) ||'"';

BIGINT

Teradata

IN -> Teradata_04.sql
SELECT '"'||cast(cast(12345 as BIGINT) as varchar(10))||'"';

Snowflake

OUT -> Teradata_04.sql
SELECT
       '"'|| LEFT(TO_VARCHAR(CAST(12345 AS BIGINT), 'TM'), 10) ||'"';

DECIMAL[(n[,m])] or NUMERIC[(n[,m])]

Teradata

IN -> Teradata_05.sql
SELECT '"'||cast(cast(12345 as DECIMAL) as varchar(10))||'"',
       '"'||cast(cast(12345 as DECIMAL(12, 2)) as varchar(10))||'"';

Snowflake

OUT -> Teradata_05.sql
SELECT
'"'|| LEFT(TO_VARCHAR(CAST(12345 AS DECIMAL), 'TM.'), 10) ||'"',
'"'|| LEFT(TO_VARCHAR(CAST(12345 AS DECIMAL(12, 2)), 'TM'), 10) ||'"';

Known Issues

  • Teradata treats the numbers between 0 and 1 differently than Snowflake. For those values, Teradata does not add the zero before the dot; meanwhile, Snowflake does.

Teradata

IN -> Teradata_06.sql
SELECT '"'||cast(cast(-0.1 as DECIMAL(12, 2)) as varchar(10))||'"' AS column1,
       '"'||cast(cast(0.1 as DECIMAL(12, 2)) as varchar(10))||'"' AS column2;

Snowflake

OUT -> Teradata_06.sql
SELECT
'"'|| LEFT(TO_VARCHAR(CAST(-0.1 AS DECIMAL(12, 2)), 'TM'), 10) ||'"' AS column1,
'"'|| LEFT(TO_VARCHAR(CAST(0.1 AS DECIMAL(12, 2)), 'TM'), 10) ||'"' AS column2;

No related EWIs.

Last updated