

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 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/)。

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

# 查詢目錄資料表
<a name="c_join_PG"></a>

**Topics**
+ [目錄查詢範例](c_join_PG_examples.md)

通常，您可以將目錄資料表和檢視 (其名稱開頭為 **PG\_** 的關係) 聯結至 Amazon Redshift 資料表和檢視。

目錄資料表使用 Amazon Redshift 不支援的各種資料類型。下列資料類型在將查詢對 Amazon Redshift 資料表聯結目錄資料表時受到支援：
+ bool
+ "char"
+ float4
+ int2
+ int4
+ int8
+ name
+ oid
+ text
+ varchar

如果您寫入加入查詢，其明確或隱含地參考擁有不受支援之資料類型的欄位，則查詢會傳回錯誤。在某些目錄資料表中使用的 SQL 函數也不受支援，除非是 PG\_SETTINGS 和 PG\_LOCKS 資料表所用的那些函數。

例如，PG\_STATS 資料表不得與 Amazon Redshift 資料表一同受到查詢，因為此功能不受支援。

下列目錄資料表和檢視提供的資訊很有用，您可以將其與 Amazon Redshift 資料表中的資訊結合在一起。因為資料類型和函數限制，部分資料表僅允許部分存取權。當您查詢可部分存取的資料表時，請小心地選取或參考其欄位。

以下資料表是可完整存取的，且未包含不受支援的函數類型：
+  [pg\_attribute](https://www.postgresql.org/docs/8.0/static/catalog-pg-attribute.html) 
+  [pg\_cast](https://www.postgresql.org/docs/8.0/static/catalog-pg-cast.html) 
+  [pg\_depend](https://www.postgresql.org/docs/8.0/static/catalog-pg-depend.html) 
+  [pg\_description](https://www.postgresql.org/docs/8.0/static/catalog-pg-description.html) 
+  [pg\_locks](https://www.postgresql.org/docs/8.0/static/view-pg-locks.html) 
+  [pg\_opclass](https://www.postgresql.org/docs/8.0/static/catalog-pg-opclass.html) 

以下資料表是可部分存取的，且包含一些不受支援類型、函數和遭截斷的文字欄位。文字欄位中的值遭截斷為 varchar(256) 值。
+  [pg\_class](https://www.postgresql.org/docs/8.0/static/catalog-pg-class.html) 
+  [pg\_constraint](https://www.postgresql.org/docs/8.0/static/catalog-pg-constraint.html) 
+  [pg\_database](https://www.postgresql.org/docs/8.0/static/catalog-pg-database.html) 
+  [pg\_group](https://www.postgresql.org/docs/8.0/static/catalog-pg-group.html) 
+  [pg\_language](https://www.postgresql.org/docs/8.0/static/catalog-pg-language.html) 
+  [pg\_namespace](https://www.postgresql.org/docs/8.0/static/catalog-pg-namespace.html) 
+  [pg\_operator](https://www.postgresql.org/docs/8.0/static/catalog-pg-operator.html) 
+  [pg\_proc](https://www.postgresql.org/docs/8.0/static/catalog-pg-proc.html) 
+  [pg\_settings](https://www.postgresql.org/docs/8.0/static/view-pg-settings.html) 
+  [pg\_statistic](https://www.postgresql.org/docs/8.0/static/catalog-pg-statistic.html) 
+  [pg\_tables](https://www.postgresql.org/docs/8.0/static/view-pg-tables.html) 
+  [pg\_type](https://www.postgresql.org/docs/8.0/static/catalog-pg-type.html) 
+  [pg\_user](https://www.postgresql.org/docs/8.0/static/view-pg-user.html) 
+  [pg\_views](https://www.postgresql.org/docs/8.0/static/view-pg-views.html) 

未在此處列出的目錄資料表為不可存取或可能未供 Amazon Redshift 管理員使用。然而，如果您的查詢不包含對 Amazon Redshift 資料表的加入時，您可以開放地查詢任何目錄資料表或檢視。

您可以使用 Postgres 目錄資料表中的 OID 欄位做為加入欄位。例如，加入條件 `pg_database.oid = stv_tbl_perm.db_id` 符合每個 PG\_DATABASE 列的內部資料庫物件 ID，內含 STV\_TBL\_PERM 資料表中可見的 DB\_ID 欄位。OID 欄位是內部主要索引鍵，當您從資料表進行選取時無法看見此欄位。目錄檢視沒有 OID 欄位。

某些 Amazon Redshift 函數必須只能在運算節點上執行。如果查詢參考的是使用者建立的資料表，SQL 會在運算節點上執行。

查詢如果只參考目錄資料表 (具有 PG 字首的資料表，例如 PG\_TABLE\_DEF)，或是未參考任何資料表，就只會在領導節點上執行。

如果使用運算節點函數的查詢未參考使用者定義的資料表或 Amazon Redshift 系統資料表傳回下列錯誤。

```
[Amazon](500310) Invalid operation: One or more of the used functions must be applied on at least one user created table.
```