TERA Mode For Strings Comparison - NO COLLATE

This section defines the translation specification for string in Tera mode without using COLLATE.

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

Description

Tera Mode for string comparison and NO COLLATE usages

The Tera Mode string comparison without the use of COLLATE will apply RTRIM and UPPER as needed. The default case specification trim behavior may be taken into account.

Sample Source Patterns

Setup data

IN -> Teradata_01.sql
CREATE TABLE employees (
    employee_id INTEGER NOT NULL,
    first_name VARCHAR(50) NOT CASESPECIFIC,
    last_name VARCHAR(50) CASESPECIFIC,
    department VARCHAR(50)
);

INSERT INTO employees(employee_id, first_name, last_name, department) VALUES (1, 'George', 'Snow', 'Sales');
INSERT INTO employees(employee_id, first_name, last_name, department) VALUES (2, 'John', 'SNOW', 'Engineering');
INSERT INTO employees(employee_id, first_name, last_name, department) VALUES (3, 'WIlle', 'SNOW', 'Human resources   ');
INSERT INTO employees(employee_id, first_name, last_name, department) VALUES (4, 'Marco', 'SnoW   ', 'EngineerinG');
INSERT INTO employees(employee_id, first_name, last_name, department) VALUES (5, 'Mary', '   ', 'SaleS  ');
INSERT INTO employees(employee_id, first_name, last_name, department) VALUES (6, 'GEORGE', '  ', 'sales  ');
INSERT INTO employees(employee_id, first_name, last_name, department) VALUES (7, 'GEORGE   ', '  ', 'salEs  ');
INSERT INTO employees(employee_id, first_name, last_name, department) VALUES (8, '    GeorgE   ', '  ', 'SalEs  ');
INSERT INTO employees (employee_id, first_name, last_name, department) VALUES (9, 'JOHN', '   SnoW', 'IT');
INSERT INTO employees (employee_id, first_name, last_name, department) VALUES (10, 'JOHN    ', 'snow', 'Finance   ');

CREATE TABLE departments (
    department_id INTEGER NOT NULL,
    department_name VARCHAR(50) NOT CASESPECIFIC,
    location VARCHAR(100) CASESPECIFIC,
    PRIMARY KEY (department_id)
);


INSERT INTO departments (department_id, department_name, location) VALUES (101, 'Information Technology', 'New York');
INSERT INTO departments (department_id, department_name, location) VALUES (102, 'Human Resources', 'Chicago');
INSERT INTO departments (department_id, department_name, location) VALUES (103, 'Sales', 'San Francisco');
INSERT INTO departments (department_id, department_name, location) VALUES (104, 'Finance', 'Boston');

Comparison operation

Case 1: Column constraint is NOT CASESPECIFIC and database mode is TERA Mode

This example demonstrates the usage of a column set up as NOT CASESPECIFIC as it is a first_name column. Even when asking for the string 'GEorge', the query execution will retrieve results in Teradata because the case specification is not considered.

To emulate this scenario in Snowflake, there are implemented two functions: RTRIM(UPPER(string_evaluation)), UPPER is required in this scenario because the string does not review the case specification.

Teradata

Snowflake

Case 2: Column constraint is CASESPECIFIC and database mode is TERA Mode

For this example, the column constraint is CASESPECIFIC, for which the example does not retrieve rows in Teradata because 'Snow' is not equal to 'SNOW'.

In Snowflake, the resulting migration points only to the use of the RTRIM function since the case specification is important.

Teradata

Snowflake

Case 3: CAST CASESPECIFIC column to NOT CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

RTRIM is required on the left side, and RTRIM is required on the right side.

Case 4: CAST NOT CASESPECIFIC column to NOT CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

Case 5: Blank spaces case. Column constraint is NOT CASESPECIFIC, database mode is TERA Mode, and using equal operation

Teradata

Snowflake

LIKE operation

This operation works differently from another one. Blank spaces must be the same quantity to retrieve information.

Case 1: Column constraint is NOT CASESPECIFIC and database mode is TERA Mode

This example is expected to display one row because the case specification is not relevant.

In Snowflake, the migration uses the ILIKE operation. This performs a case-insensitive comparison.

Teradata

Snowflake

Case 2: Column constraint is CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

Case 3: CAST CASESPECIFIC column to NOT CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

Case 4: CAST NOT CASESPECIFIC column to NOT CASESPECIFIC and database mode is ANSI Mode

This case requires the translation to ILIKE.

Teradata

Snowflake

IN Operation

Case 1: Column constraint is NOT CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

Case 2: Column constraint is CASESPECIFIC and database mode is TERA Mode

For this example, the usage of the UPPER function is not required since, in the Teradata database, the case specification is relevant to the results.

Teradata

Snowflake

ORDER BY clause

Case 1: Column constraint is NOT CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

Case 2: Column constraint is CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

GROUP BY clause

About the column behavior

Assume a table and data as follows:

Notice that this sample does not allow inserting values with upper and lower case letters in the NOT CASESPECIFIC column because it takes it as the same value. Because the column does not supervise the case specification, the 'GEORGE' and 'george' values are checked as the same information.

The following rows are taken as duplicated row errors:

Case 1: Column constraint is NOT CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

Case 2: Column constraint is CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

HAVING clause

The HAVING clause will use the patterns in:

  • Evaluation operations.

    • For example: =, !=, <, >.

  • LIKE operation.

  • IN Operation.

  • CAST to evaluation operation.

  • CAST to LIKE operation.

The following sample showcases a pattern with evaluation operation.

Sample: Column constraint is CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

CASE WHEN statement

The CASE WHEN statement will use the patterns described in:

  • Evaluation operations.

    • For example: =, !=, <, >.

  • LIKE operation.

  • IN Operation.

  • CAST to evaluation operation.

  • CAST to LIKE operation.

The following sample showcases a pattern with evaluation operation.

Teradata

Snowflake

JOIN clause

The JOIN statement will use the patterns described in:

  • Evaluation operations.

    • For example: =, !=, <, >.

  • LIKE operation.

  • IN Operation.

  • CAST to evaluation operation.

  • CAST to LIKE operation.

The following sample showcases a pattern with evaluation operation.

Sample: Column constraint is NOT CASESPECIFIC and database mode is TERA Mode

Teradata

Snowflake

Known Issues

  1. there are some mode-specific SQL statement restrictions: BEGIN TRANSACTION, END TRANSACTION, COMMIT [WORK].

  2. Data insertion may differ in Snowflake since the case specification is not bound to the column declaration.

  3. GROUP BY may differ in order, but group the correct values.

  4. ORDER BY behaves differently in Snowflake.

  5. If a function has a TRIM() from the source code, this workaround will add the required functions to the source code. So, RTRIM will be applied to the TRIM() source function.

SSC-EWI-TD0007: GROUP BY IS NOT EQUIVALENT IN TERADATA MODE

Last updated