

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

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

# STV\_TBL\_PERM
<a name="r_STV_TBL_PERM"></a>

STV\_TBL\_PERM 資料表包含 Amazon Redshift 中永久資料表的相關資訊，其中包括使用者為目前工作階段建立的暫時資料表。STV\_TBL\_PERM 包含所有資料庫中所有資料表的資訊。

此資料表不同於 [STV\_TBL\_TRANS](r_STV_TBL_TRANS.md)，它包含系統在查詢處理過程中建立之暫時性資料庫的相關資訊。

只有超級使用者可以看到 STV\_TBL\_PERM。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

## 資料表欄
<a name="r_STV_TBL_PERM-table-columns"></a>


| 欄名稱  | 資料類型  | Description  | 
| --- | --- | --- | 
| 分割  | integer  | 配置至資料表的節點分割。 | 
| id  | integer  | 表格 ID。 | 
| name  | character(72)  | 資料表名稱. | 
| rows  | bigint  | 分割中的資料列數。 | 
| sorted\_rows  | bigint  | 已在磁碟上排序之分割中的資料列數。如果此數字不符合 ROWS 數字，請清空資料表以重新排序資料列。 | 
| temp  | integer  | 該資料表是否為暫時資料表。0 = false；1 = true。 | 
| db\_id  | integer  | 用於建立資料表之資料庫的 ID。 | 
| insert\_pristine | integer  | 供內部使用。 | 
| delete\_pristine | integer  | 供內部使用。 | 
| backup | integer  | 用於指出該資料表是否包含在叢集快照中的值。0 = no；1 = yes。如需詳細資訊，請參閱 CREATE TABLE 命令的 [BACKUP](r_CREATE_TABLE_NEW.md#create-table-backup) 參數。 | 
| dist\_style | integer  | 切片所屬資料表的分散樣式。如需這些值的詳細資訊，請參閱[檢視分佈樣式](viewing-distribution-styles.md)。如需分散樣式的資訊，請參閱[分佈樣式](c_choosing_dist_sort.md)。 | 
| block\_count | integer  | 分割使用的區塊數目。無法計算區塊計數時，值為 -1。 | 

## 範例查詢
<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\_TBL\_PERM 資料表中 ROWS 欄位的總和 (SUM) 可能會與 COUNT(\*) 結果不相符。例如，如果從 VENUE 刪除 2 個資料列，COUNT(\*) 結果為 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\_TBL\_PERM 中的資料，請執行完整清空 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)
```