Optimizing Teradata Joins: Handling Skewed Workloads with Partial Redistribution and Partial Duplication

tune4

How does Teradata handle Skew in Joins? The imbalanced workload is a primary issue that must be addressed in performance optimization. Efficient optimization is crucial for join steps due to the possibility of Teradata transferring significant data volumes between AMPs. The optimizer can perform joins separately for primary index values that are skewed and those …

Read more

Choosing the Right Teradata Data Types

tune2

How Do I Select The Appropriate Data Type In Teradata? Converting datatypes incurs substantial costs and demands significant CPU resources when dealing with extensive tables. Incorrect data type selection hinders the execution plan. This article will discuss selecting appropriate data types for optimal performance. Consistency in selecting data types across different tables is crucial, as …

Read more

Teradata Referential Integrity: What it is and Why You Need it for Data Consistency and Performance

design3

Introduction to Teradata Referential Integrity Teradata implements 3 Types of Referential Integrity. 1. What is Standard Referential Integrity? The Standard Referential Integrity checks every Row INSERT, DELETE, or UPDATE immediately to ensure referential integrity. A reference index sub-table is required for referential integrity. Violation of referential integrity results in the failure of execution and generates …

Read more

Teradata Table Design Checklist: Primary Index, Character Set, and Data Type Considerations

tune3

Teradata Table Design Checklist As creating tables is a frequent task, I deemed it necessary to provide a checklist. 1. Primary Index Or NOPI Table? The Primary Index serves multiple purposes, primarily functioning as the primary access path to the data and being optimized for an even distribution of rows. However, designing a table without …

Read more

Teradata Query Parallelism: A closer look at how Teradata’s shared-nothing architecture and parallel processing capabilities deliver exceptional performance.

arch2

Teradata Query Parallelism A query on a Teradata system runs in parallel at every step, whether for joining, sorting, or aggregating data. Teradata’s uniqueness lies in its ability to apply parallelism at every step of the query process. This advantage resulted from its architectural design, which integrated high levels of parallelism from the start, even …

Read more

The Importance of Teradata Surrogate Keys

design3

What are Teradata Surrogate Keys? A Teradata Surrogate Key is an artificial key that maps to a natural key. It is usually of the data type INTEGER or BIGINT and is represented by a single column. The natural key can consist of multiple columns. The surrogate key is generated automatically and is represented by an …

Read more

Advanced GROUPING Methods in Teradata SQL: GROUP BY GROUPING SETS, ROLLUP, and CUBE

sql2

Teradata SQL and Advanced GROUPING Functions The advanced GROUPING functions will be demonstrated through the following example. The foundation of this demonstration is a table consisting of the flight count for each aircraft and date: CREATE MULTISET TABLE Flights ( PLANE AS BIGINT NOT NULL, FLIGHTDATE AS DATE NOT NULL, NR_FLIGHTS INTEGER NOT NULL ) …

Read more

Achieve Incredible Teradata Join Performance

tune2

Executive summaryGUEST POST BY ARTEMIY KOZYR Today I shed some light on how Data Warehousing lies at the core of Retail Banking operations. We will see the actual case of vital marketing process malfunction and dive deep under the surface level to comprehend data alchemy technical issues. You will learn how to approach such issues, …

Read more

How to Optimize Teradata Statistics and Avoid Heuristics: A Case Study

tune1

The Optimizer typically excels in utilizing statistics, yet examining the execution plan and cardinality estimations can sometimes be beneficial. Since Teradata 14.10, I have habitually included the SHOW STATISTICS statement in my considerations. The resulting metrics can aid in identifying statistical issues. Teradata Statistics – Avoid the Heuristics This case study demonstrates how the Optimizer …

Read more

Learn Teradata Indexing Techniques in this 2-Hour Video Course

tune2

Introduction

Teradata SQL lacks a built-in function to determine the ASCII code of a character. But fear not, for there exists a query workaround to this dilemma. This blog post will guide you through the process of using a straightforward SQL query in Teradata to find the ASCII code of a character.

The solution is as follows:

We use the Teradata SQL function CHAR2HEXINT to obtain a hexadecimal value for a character. Our objective is to convert this hexadecimal value to its decimal counterpart, which signifies the character’s ASCII code.

This SQL query accomplishes the task.

SELECT
CASE SUBSTRING(CHAR2HEXINT('B') FROM 3 FOR 1)
WHEN '0' THEN 0
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN '4' THEN 4
WHEN '5' THEN 5
WHEN '6' THEN 6
WHEN '7' THEN 7
WHEN '8' THEN 8
WHEN '9' THEN 9
WHEN 'A' THEN 10
WHEN 'B' THEN 11
WHEN 'C' THEN 12
WHEN 'D' THEN 13
WHEN 'E' THEN 14
WHEN 'F' THEN 15
END * 16 +
CASE SUBSTRING(CHAR2HEXINT('B') FROM 4 FOR 1)
WHEN '0' THEN 0
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN '4' THEN 4
WHEN '5' THEN 5
WHEN '6' THEN 6
WHEN '7' THEN 7
WHEN '8' THEN 8
WHEN '9' THEN 9
WHEN 'A' THEN 10
WHEN 'B' THEN 11
WHEN 'C' THEN 12
WHEN 'D' THEN 13
WHEN 'E' THEN 14
WHEN 'F' THEN 15
END

Using a CASE statement, the query extracts two hexadecimal digits with the SUBSTRING function and converts them to decimal values. It then calculates the character’s ASCII code by multiplying the first digit’s decimal value by 16 and adding the second digit’s decimal value.

Conclusion

Teradata SQL lacks a dedicated feature for determining the ASCII code of a given character. However, this blog post offers a straightforward and efficient workaround for this issue. By utilizing the CHAR2HEXINT function and performing basic arithmetic operations, you can effectively determine the ASCII code of any character within your Teradata SQL queries.

DWHPro

Expert network for enterprise data platforms. Senior consultants, project teams built for your challenge — across Teradata, Snowflake, Databricks, and more.

📍Vienna, Austria & Jacksonville, Florida

Quick Links
Services Team Teradata Book Blog Contact Us
Connect
LinkedIn → [email protected]
Newsletter

Join 4,000+ data professionals.
Weekly insights on Teradata, Snowflake & data architecture.