SUPER 設定 - Amazon Redshift

SUPER 設定

Amazon Redshift SUPER データ型と PartiQL を使用する場合は、SUPER 設定に関する次の考慮事項に注意してください。

SUPER の lax および strict モード

SUPER データをクエリすると、パス式が実際の SUPER データ構造と一致しないことがあります。オブジェクトまたは配列の要素が存在しないメンバーにアクセスしようとすると、クエリがデフォルトの lax モードで実行されると、Amazon Redshift は NULL 値を返します。strict モードでクエリを実行すると、Amazon Redshift はエラーを返します。次のセッションパラメータを設定して、lax モードをオンまたはオフに設定できます。

次の例では、セッションパラメータを使用して lax モードを有効にします。

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 フィールドへのアクセス

JSON 属性名が大文字、または大小文字が混在している場合は、大文字と小文字を区別して SUPER 型構造をナビゲートできるようにする必要があります。そのためには、enable_case_sensitive_identifier を TRUE に設定して、大文字、および大小文字が混在する属性名を二重引用符で囲みます。enable_case_sensitive_super_attribute を TRUE に設定することもできます。この場合、クエリで大文字および大小文字が混在する属性名を二重引用符で囲まずに使用することができます。

次の例では、enable_case_sensitive_identifier にクエリデータを設定する方法を説明しています。

SET enable_case_sensitive_identifier to TRUE; -- Accessing JSON attribute names with uppercase and mixedcase 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 mixedcase 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)

次の例では、enable_case_sensitive_super_attribute にクエリデータを設定する方法を説明しています。

SET enable_case_sensitive_super_attribute to TRUE; -- Accessing JSON attribute names with uppercase and mixedcase 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_super_attribute; -- After resetting enable_case_sensitive_super_attribute, the query now returns NULL for ITEMS.Name (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 の解析オプション

JSON_PARSE 関数を使用して JSON 文字列を SUPER 値に解析する場合、特定の制限が適用されます。

  • 同じ属性名を同じオブジェクトに表示することはできませんが、ネストされたオブジェクトには表示できます。json_parse_dedup_attributes 設定オプションを使用すると、JSON_PARSE はエラーを返す代わりに、重複属性の最後の出現のみを保持できます。

  • 文字列値は、システムの最大 varchar サイズである 65535 バイトを超えることはできません。json_parse_truncate_strings 設定オプションを使用すると、JSON_PARSE() は、エラーを返さずに、この制限より長い文字列を自動的に切り捨てることができます。この動作は文字列値のみに影響し、属性名には影響しません。

JSON_PARSE 関数の詳細については、「JSON_PARSE 関数」を参照してください。

次の例は、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