17.05 - Example: Effects of Default and User-Specified Case Sensitivity on the Ordering of a Result Set - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1146-175K
Language
English (United States)

The following statements create and populate table t:

     CREATE TABLE t (
       a CHAR(4) NOT CASESPECIFIC,
       b BYTEINT)
     PRIMARY INDEX (a,b);
     INSERT INTO t VALUES ('AAAA', 1);
     INSERT INTO t VALUES ('aaaa', 2);
     INSERT INTO t VALUES ('BBBB', 3);
     INSERT INTO t VALUES ('bbbb', 4);

If the default handling of case is allowed, the following statement produces the following results table.

     SELECT *
     FROM t
     ORDER BY a;
     a         b
     ----     ---
     AAAA      1
     aaaa      2
     BBBB      3
     bbbb      4

On the other hand, when you specify CASESPECIFIC for the query, the results are one of the results tables immediately following the example SELECT statements, depending on the collation sequence in effect for the current session.

     SELECT *
     FROM t
     ORDER BY CAST(a AS CASESPECIFIC);

or

     SELECT CAST(a AS CASESPECIFIC), b
     FROM t
     ORDER BY 1;
EBCDIC ASCII MULTINATIONAL
A B A B A B
---- ---- ---- ---- ---- ----
aaaa 2 AAAA 1 aaaa 2
bbbb 4 BBBB 3 AAAA 1
AAAA 1 aaaa 2 bbbb 4
BBBB 3 bbbb 4 BBBB 3