标准 SQL 和 Teradata 转换语法之间的语义差异

Semantic difference between standard SQL and Teradata cast syntax

我正在尝试了解以下两种语法之间的区别,它们在将字符串转换为整数时似乎在做同样的事情:

SELECT CAST('1' AS INTEGER), '1' (INTEGER)

导致:

|'1'|'1'|
|---|---|
|1  |1  |

但是他们在链接转换时不做同样的事情:

SELECT CAST(CAST('1' AS INTEGER) AS VARCHAR(3)), ('1' (INTEGER)) (VARCHAR(3))

我现在得到:

|'1'|'1'|
|---|---|
|1  |   |

第二列包含一个空字符串,不为空。这两种语法之间是否存在语义差异,或者这只是一个错误?

我使用的是版本 16.20.05.01

如评论中所述(没有人想回答?),有记录的差异 "How CAST Differs from Teradata Conversion Syntax"

部分的行为

具体来说:

Using Teradata conversion syntax (that is, not using CAST) for explicit conversion of numeric -to-character data requires caution.

The process is as follows:

  1. Convert the numeric value to a character string using the default or specified FORMAT for the numeric value. Leading and trailing pad characters are not trimmed.

  2. Extend to the right with pad characters if required, or truncate from the right if required, to conform to the target length specification. If non-pad characters are truncated, no string truncation error is reported.