

 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/)。

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

# PG\_TABLE\_DEF
<a name="r_PG_TABLE_DEF"></a>

儲存資料表欄位的相關資訊。

PG\_TABLE\_DEF 僅傳回使用者可見之資料表的相關資訊。如果 PG\_TABLE\_DEF 未傳回預期的結果，確認 [search\_path](r_search_path.md) 參數是否正確設定為包含相關的結構描述。

您可以使用 [SVV\_TABLE\_INFO](r_SVV_TABLE_INFO.md) 來檢視資料表的更全面性資訊，包括資料配送偏度、索引鍵配送偏度、資料表大小、統計等方面的問題。

## 資料表欄
<a name="r_PG_TABLE_DEF-table-columns2"></a>


| 欄名稱  | 資料類型  | 說明  | 
| --- | --- | --- | 
| 結構描述名稱 | name | 結構描述名稱。 | 
| 資料表名稱 | name | 資料表名稱. | 
| 欄位 | name  | 資料欄名稱。 | 
| type  | text | 欄位資料類型。 | 
| 編碼  | character(32)  | 欄位編碼。 | 
| distkey  | boolean | 若此欄位是資料表的分佈索引鍵，則為 true。 | 
| sortkey | integer  | 排序索引鍵中的欄位順序。如果資料表使用的是複合排序索引鍵，則排序索引鍵部分的所有欄位會有正值，指示排序索引鍵中欄位的位置。如果資料表使用的是交錯的排序索引鍵，則排序索引鍵部分的每個欄會有交替為正或負的值，其中絕對值表示排序索引鍵中的欄位置。若為 0，則欄位不是排序索引鍵的一部分。 | 
| notnull | boolean  | 如果欄位有 NOT NULL 限制，則為 true。 | 

## 範例
<a name="r_PG_TABLE_DEF-example2"></a>

下列範例顯示 LINEORDER\_COMPOUND 資料表的複合排序索引鍵欄位。

```
select "column", type, encoding, distkey, sortkey, "notnull" 
from pg_table_def
where tablename = 'lineorder_compound' 
and sortkey <> 0;

column       | type    | encoding | distkey | sortkey | notnull
-------------+---------+----------+---------+---------+--------
lo_orderkey  | integer | delta32k | false   |       1 | true   
lo_custkey   | integer | none     | false   |       2 | true   
lo_partkey   | integer | none     | true    |       3 | true   
lo_suppkey   | integer | delta32k | false   |       4 | true   
lo_orderdate | integer | delta    | false   |       5 | true   
(5 rows)
```

 下列範例顯示 LINEORDER\_INTERLEAVED 資料表的交錯排序索引鍵欄位。

```
select "column", type, encoding, distkey, sortkey, "notnull" 
from pg_table_def
where tablename = 'lineorder_interleaved' 
and sortkey <> 0;

column       | type    | encoding | distkey | sortkey | notnull
-------------+---------+----------+---------+---------+--------
lo_orderkey  | integer | delta32k | false   |      -1 | true   
lo_custkey   | integer | none     | false   |       2 | true   
lo_partkey   | integer | none     | true    |      -3 | true   
lo_suppkey   | integer | delta32k | false   |       4 | true   
lo_orderdate | integer | delta    | false   |      -5 | true   
(5 rows)
```

PG\_TABLE\_DEF 將僅傳回在搜尋路徑中包含之結構描述中資料表的相關資訊。如需詳細資訊，請參閱[search\_path](r_search_path.md)。

例如，假設您建立新結構描述和新資料表，以及查詢 PG\_TABLE\_DEF。

```
create schema demo;
create table demo.demotable (one int);
select * from pg_table_def where tablename = 'demotable';

schemaname|tablename|column| type | encoding | distkey | sortkey | notnull 
----------+---------+------+------+----------+---------+---------+--------
```

查詢未傳回新資料表的任何列。檢查 `search_path` 的設定。

```
show search_path;

  search_path
---------------
 $user, public
(1 row)
```

將 `demo` 結構描述新增至搜尋路徑中並再次執行查詢。

```
set search_path to '$user', 'public', 'demo';

select * from pg_table_def where tablename = 'demotable';

schemaname| tablename |column|  type   | encoding |distkey|sortkey| notnull
----------+-----------+------+---------+----------+-------+-------+--------
demo      | demotable | one  | integer | none     | f     |     0 | f
(1 row)
```