

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 Python UDF。现有的 Python UDF 将继续正常运行至 2026 年 6 月 30 日。有关更多信息，请参阅[博客文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

# Apache Iceberg 表支持的数据类型
<a name="querying-iceberg-supported-data-types"></a>

本主题介绍 Redshift Spectrum 可以从采用 Apache Iceberg 格式的表中读取的受支持的数据类型。

Amazon Redshift 可以查询包含以下数据类型的 Iceberg 表：

```
binary
boolean
date
decimal
double
float
int
list
long
map
string
struct
timestamp without time zone
```

创建和定义 Iceberg 表时，请在 SQL 语句中使用 Amazon Redshift 数据类型名称。Redshift 会自动将它们映射到相应的 Iceberg 类型。有关 Iceberg 数据类型的更多信息，请参阅 Apache 文档中的 [Schemas for Iceberg](https://iceberg.apache.org/docs/latest/schemas/)。

从 Iceberg 表进行读取时，Iceberg 数据类型会映射到 Redshift 数据类型，如下表所示：


****  

| Iceberg 类型 | Amazon Redshift 类型 | 备注 | 
| --- | --- | --- | 
| boolean | boolean | - | 
| - | tinyint | Iceberg 表不支持。 | 
| - | smallint | Iceberg 表不支持。 | 
| int | int | - | 
| long | bigint | - | 
| double | double precision | - | 
| float | real | - | 
| decimal(P, S) | decimal(P, S) | P 表示精度，S 表示小数位数。 | 
| - | char | Iceberg 表不支持。 | 
| string | varchar(16384) | 超过 16384 个字符的字符串会被截断为 16384 个字符。 | 
| binary | varbyte(64000) | - | 
| date | date | - | 
| time | - | - | 
| timestamp | timestamp | - | 
| timestamptz | timestampz | - | 
| list<E> | SUPER | - | 
| map<K,V> | SUPER | - | 
| struct<...> | SUPER | - | 
| fixed(L) | - | Redshift Spectrum 目前不支持 fixed(L) 类型。 | 
| uuid | - | Redshift Spectrum 目前不支持 uuid 类型。 | 
| variant | - | Amazon Redshift 不支持 Iceberg V3。 | 
| geometry | - | Amazon Redshift 不支持 Iceberg V3。 | 
| geography | - | Amazon Redshift 不支持 Iceberg V3。 | 
| timestamp\$1ns | - | Amazon Redshift 不支持 Iceberg V3。 | 
| timestamptz\$1ns | - | Amazon Redshift 不支持 Iceberg V3。 | 
| Unknown | - | Amazon Redshift 不支持 Iceberg V3。 | 

从 Redshift 创建 Iceberg 表时，支持以下数据类型。下表显示 Redshift 数据类型到 Iceberg 数据类型的映射。


****  

| Amazon Redshift 类型 | Amazon Redshift 别名 | Iceberg 类型 | 备注 | 
| --- | --- | --- | --- | 
| integer | int, int4 | int | - | 
| bigint | int8 | long | - | 
| decimal | numeric | decimal(p,S) | - | 
| real | float4 | float | - | 
| double precision | float8, float | double | - | 
| varchar | charactter varying,nvarchar, text | string | 创建 Iceberg 表时不支持 varchar(n) 数据类型。 | 
| date | - | date | - | 
| timestamp | - | timestamp | - | 
| timestamptz | - | timestamptz | - | 
| boolean | - | boolean | - | 

写入 Iceberg 表时，在上表中提到的数据类型之外，一些源数据类型还会进行类型提升，使其成为兼容的 Iceberg 类型，如下表所示。


| Amazon Redshift 类型 | Iceberg 类型 | 
| --- | --- | 
|  `tinyint`  |  `int`  | 
|  `smallint`  |  `int`  | 
|  `varchar(n)`  |  `string`  | 

尝试使用不支持的数据类型会导致语法错误。使用 `CREATE TABLE AS SELECT` 子句创建 Iceberg 表时，您可以添加显式强制转换来解决类型的不同。

例如，假设您有采用以下架构的 Redshift RMS 表：

```
CREATE TABLE rms_t (c1 int, c2 char(20));
```

如果要使用 `rms_t` 作为源来创建 Iceberg 表，则您需要对 `c2` 列进行显式强制转换，因为 `varchar(n)` 类型不受支持：

```
CREATE TABLE ext_schema.iceberg_t AS SELECT c1, c2::varchar FROM rms_t;
```

有关 Amazon Redshift 中的数据类型的更多信息，请参阅[数据类型](c_Supported_data_types.md)。