

 从补丁 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/)。

# SUPER 配置
<a name="super-configurations"></a>

您可以为特定场景配置 SUPER 数据。以下各节将详细介绍如何根据数据格式要求选择和应用适当的 SUPER 配置。

**Topics**
+ [宽松和严格的 SUPER 模式](#lax-strict-modes)
+ [访问具有大写和混合大小写字段名称或属性的 JSON 字段](#upper-mixed-case)
+ [解析 SUPER 的选项](#parsing-options-super)

## 宽松和严格的 SUPER 模式
<a name="lax-strict-modes"></a>

当您查询 SUPER 数据时，路径表达式可能不匹配实际的 SUPER 数据结构。当您尝试访问对象或数组元素的不存在成员时，如果您的查询在默认宽松模式下运行，Amazon Redshift 将返回 NULL 值。如果您在严格模式下运行查询，Amazon Redshift 将返回错误。可以将以下会话参数设置为打开或关闭宽松模式。

以下示例使用会话参数启用宽松模式。

```
SET navigate_super_null_on_error=ON;  --default lax mode for navigation

SET cast_super_null_on_error=ON;  --default lax mode for casting

SET parse_super_null_on_error=OFF;  --default strict mode for ingestion
```

## 访问具有大写和混合大小写字段名称或属性的 JSON 字段
<a name="upper-mixed-case"></a>

当 JSON 属性名称采用大写或混合大小写时，必须能够以区分大小写的方式导航 SUPER 类型结构。为此，可以将 `enable_case_sensitive_identifier` 配置为 TRUE，并将大写和混合大小写的属性名称用双引号括起来。

以下示例说明如何设置 `enable_case_sensitive_identifier` 来查询数据。

```
SET enable_case_sensitive_identifier to TRUE;
 
-- Accessing JSON attribute names with uppercase and mixed-case names
SELECT json_table.data."ITEMS"."Name",
       json_table.data."price"
FROM
  (SELECT json_parse('{"ITEMS":{"Name":"TV"}, "price": 345}') AS data) AS json_table;

 Name | price
------+-------
 "TV" | 345
(1 row)
 
RESET enable_case_sensitive_identifier;
 
-- After resetting the above configuration, the following query accessing JSON attribute names with uppercase and mixed-case names should return null (if in lax mode).
SELECT json_table.data."ITEMS"."Name",
       json_table.data."price"
FROM
  (SELECT json_parse('{"ITEMS":{"Name":"TV"}, "price": 345}') AS data) AS json_table;

 name | price 
------+-------
      | 345
(1 row)
```

## 解析 SUPER 的选项
<a name="parsing-options-super"></a>

当您使用 JSON\$1PARSE 函数将 JSON 字符串解析为 SUPER 值时，某些限制适用：
+ 相同的属性名称不能出现在同一个对象中，但可以出现在嵌套对象中。`json_parse_dedup_attributes` 配置选项允许 JSON\$1PARSE 仅保留最后一次出现的重复属性，而不是返回错误。
+ SUPER 对象中的单个字符串文本的大小限制为 1600 万个字节。`json_parse_truncate_strings` 配置选项允许 JSON\$1PARSE() 自动截断超过此限制的字符串，而不会返回错误。此行为仅影响字符串值，而不影响属性名称。

有关 JSON\$1PARSE 函数的更多信息，请参阅 [JSON\$1PARSE 函数](JSON_PARSE.md)。

以下示例显示如何将 `json_parse_dedup_attributes` 配置选项设置为默认行为，即针对重复属性返回错误。

```
SET json_parse_dedup_attributes=OFF;  --default behavior of returning error instead of de-duplicating attributes
```

下面的示例显示如何设置 `json_parse_truncate_strings` 配置选项以实现默认行为，即针对长度超过此限制的字符串返回错误。

```
SET json_parse_truncate_strings=OFF;  --default behavior of returning error instead of truncating strings
```