

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 Python UDF。现有的 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\$1TABLE\$1DEF
<a name="r_PG_TABLE_DEF"></a>

存储有关表列的信息。

PG\$1TABLE\$1DEF 仅返回有关对用户可见的表的信息。如果 PG\$1TABLE\$1DEF 未返回预期结果，则验证 [search\$1path](r_search_path.md) 参数是否正确设置为包含相关 schemas。

可使用 [SVV\$1TABLE\$1INFO](r_SVV_TABLE_INFO.md) 查看有关表的更多信息，包括数据分配偏斜、密钥分配偏斜、表大小和统计数据。

## 表列
<a name="r_PG_TABLE_DEF-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/redshift/latest/dg/r_PG_TABLE_DEF.html)

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

以下示例显示 LINEORDER\$1COMPOUND 表的复合排序键列。

```
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\$1INTERLEAVED 表的交错排序键列。

```
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\$1TABLE\$1DEF 将仅返回搜索路径中包含的 schema 中的表的信息。有关更多信息，请参阅 [search\$1path](r_search_path.md)。

例如，假定您创建一个新 schema 和一个新表，然后查询 PG\$1TABLE\$1DEF。

```
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)
```