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

SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qtb1554762060450.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

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