enable_case_sensitive_identifier - Amazon Redshift

Amazon Redshift 自 2025 年 11 月 1 日起不再支援建立新的 Python UDF。如果您想要使用 Python UDF,請在該日期之前建立 UDF。現有 Python UDF 將繼續正常運作。如需詳細資訊,請參閱部落格文章

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

enable_case_sensitive_identifier

值 (粗體為預設值)

true、false

Description

組態值會決定資料庫、結構描述、資料表和欄的名稱識別碼是否區分大小寫。當您用雙引號括住名稱識別碼,並將 enable_case_sensitive_identifier 設定為 true 時,識別碼的大小寫就會保留。若您未用雙引號括住識別碼,或將 enable_case_sensitive_identifier 設定為 false,則名稱識別碼的大小寫不會保留,而會轉換為小寫。

無論 enable_case_sensitive_identifier 組態選項的設定為何,都會保留以雙引號括住的 username 大小寫。

範例

下列範例說明如何為資料表和資料欄名稱建立及使用區分大小寫的識別碼。

-- To create and use case sensitive identifiers SET enable_case_sensitive_identifier TO true; -- Create tables and columns with case sensitive identifiers CREATE TABLE public."MixedCasedTable" ("MixedCasedColumn" int); INSERT INTO public."MixedCasedTable" VALUES (1); INSERT INTO public."MixedCasedTable" VALUES (2); INSERT INTO public."MixedCasedTable" VALUES (3); INSERT INTO public."MixedCasedTable" VALUES (4); INSERT INTO public."MixedCasedTable" VALUES (5); -- Now query with case sensitive identifiers SELECT "MixedCasedColumn" FROM public."MixedCasedTable"; MixedCasedColumn ------------------ 1 2 3 4 5 (5 rows) SELECT * FROM public."MixedCasedTable" WHERE "MixedCasedColumn" = 1; mixedcasedcolumn ------------------ 1 (1 row)

下列範例說明未保留識別碼大小寫的時機。

-- To not use case sensitive identifiers RESET enable_case_sensitive_identifier; -- Mixed case identifiers are lowercased despite double quotation marks CREATE TABLE "MixedCasedTable2" ("MixedCasedColumn" int); CREATE TABLE MixedCasedTable2 (MixedCasedColumn int); ERROR: Relation "mixedcasedtable2" already exists SELECT "MixedCasedColumn" FROM "MixedCasedTable2"; mixedcasedcolumn ------------------ (0 rows) SELECT MixedCasedColumn FROM MixedCasedTable2; mixedcasedcolumn ------------------ (0 rows)

使用須知

  • 如果您對具體化視觀表使用自動重新整理,建議您在叢集或工作群組的參數群組中設定 enable_case_sensitive_identifier 值。這可確保在重新整理具體化視觀表時 enable_case_sensitive_identifier 保持不變。如需重新整理具體化視觀表的相關資訊,請參閱 重新整理具體化視觀表。如需在參數群組中設定組態值的相關資訊,請參閱《Amazon Redshift 管理指南》中的 Amazon Redshift 參數群組

  • 如果您使用的是資料列層級安全或動態資料遮罩功能,建議您在叢集或工作群組的參數群組中設定 enable_case_sensitive_identifier 值。這樣可確保在建立和附加政策的過程中 enable_case_sensitive_identifier 保持不變,然後查詢已套用政策的關係。如需有關資料列層級安全性詳細資訊,請參閱 資料列層級安全性。如需動態資料遮罩的詳細資訊,請參閱 動態資料遮罩

  • 當您將 enable_case_sensitive_identifier 設定為 on 並建立資料表時,您可以設定區分大小寫的資料欄名稱。當您將 enable_case_sensitive_identifier 設定為 off 並查詢資料表時,資料欄名稱會被變更為小寫。這可能會在 enable_case_sensitive_identifier 設定為 on 時產生不同的查詢結果。請思考下列範例:

    SET enable_case_sensitive_identifier TO on; --Amazon Redshift preserves case for column names and other identifiers. --Create a table with two columns that are identical except for the case. CREATE TABLE t ("c" int, "C" int); INSERT INTO t VALUES (1, 2); SELECT * FROM t; c | C ---+--- 1 | 2 (1 row) SET enable_case_sensitive_identifier TO off; --Amazon Redshift no longer preserves case for column names and other identifiers. SELECT * FROM t; c | c ---+--- 1 | 1 (1 row)
  • 我們建議一般使用者查詢具有動態資料遮罩或資料列層級安全政策的資料表時,使用預設的 enable_case_sensitive_identifier 設定。如需有關資料列層級安全性詳細資訊,請參閱 資料列層級安全性。如需動態資料遮罩的詳細資訊,請參閱 動態資料遮罩

  • 若要使用點標記法參考混合大小寫的識別碼,請用雙引號括住每個區分大小寫的識別碼。例如 public."MixedCasedTable"."MixedCasedColumn"