

 从补丁 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/)。

# STV\$1TBL\$1PERM
<a name="r_STV_TBL_PERM"></a>

STV\$1TBL\$1PERM 表包含有关 Amazon Redshift 中永久表的信息，其中包括用户为当前会话创建的临时表。STV\$1TBL\$1PERM 包含所有数据库中的所有表的信息。

此表不同于 [STV\$1TBL\$1TRANS](r_STV_TBL_TRANS.md)，后者包含有关系统在查询处理期间创建的临时数据库表的信息。

STV\$1TBL\$1PERM 仅对超级用户可见。有关更多信息，请参阅 [系统表和视图中的数据可见性](cm_chap_system-tables.md#c_visibility-of-data)。

## 表列
<a name="r_STV_TBL_PERM-table-columns"></a>

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

## 示例查询
<a name="r_STV_TBL_PERM-sample-queries"></a>

以下查询返回不同表 ID 和名称的列表：

```
select distinct id, name
from stv_tbl_perm order by name;

   id   |          name
--------+-------------------------
 100571 | category
 100575 | date
 100580 | event
 100596 | listing
 100003 | padb_config_harvest
 100612 | sales
...
```

其他系统表使用表 ID，因此知道特定表对应于哪个表 ID 会非常有用。在此示例中，SELECT DISTINCT 用于删除重复项（表分布在多个分片中）。

要确定 VENUE 表中每一列所使用的块数，请键入以下查询：

```
select col, count(*)
from stv_blocklist, stv_tbl_perm
where stv_blocklist.tbl = stv_tbl_perm.id
and stv_blocklist.slice = stv_tbl_perm.slice
and stv_tbl_perm.name = 'venue'
group by col
order by col;

 col | count
-----+-------
   0 |     8
   1 |     8
   2 |     8
   3 |     8
   4 |     8
   5 |     8
   6 |     8
   7 |     8
(8 rows)
```

## 使用说明
<a name="r_STV_TBL_PERM-usage-notes"></a>

ROWS 列包括尚未真空化（或者已真空化但使用 SORT ONLY 选项）的已删除行的计数。因此，当您直接查询给定表时，STV\$1TBL\$1PERM 表中的 ROWS 列的 SUM 可能与 COUNT(\$1) 结果不符。例如，如果从 VENUE 中删除了两行，则 COUNT(\$1) 结果为 200，但 SUM(ROWS) 结果仍为 202：

```
delete from venue
where venueid in (1,2);

select count(*) from venue;
count
-------
200
(1 row)

select trim(name) tablename, sum(rows)
from stv_tbl_perm where name='venue' group by name;

tablename | sum
-----------+-----
venue     | 202
(1 row)
```

要同步 STV\$1TBL\$1PERM 中的数据，请对 VENUE 表运行完全真空化。

```
vacuum venue;

select trim(name) tablename, sum(rows)
from stv_tbl_perm
where name='venue'
group by name;

tablename | sum
-----------+-----
venue     | 200
(1 row)
```