Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊,請參閱部落格文章
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
SUPER 組態
您可以針對特定案例設定 SUPER 資料。下列各節提供根據資料格式需求選擇和套用適當 SUPER 組態的詳細資訊。
SUPER 的寬鬆和嚴格模式
當您查詢 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 欄位
當您的 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 的剖析選項
當您使用 JSON_PARSE 函數將 JSON 字串剖析為 SUPER 值時,適用某些限制:
相同的屬性名稱不能出現在相同物件中,但可以出現在巢狀物件中。
json_parse_dedup_attributes組態選項允許 JSON_PARSE 僅保留最後一次出現的重複屬性,而不是傳回錯誤。SUPER 物件中的個別字串常值的大小限制為 16,000,000 個位元組。
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