

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

# SYS\$1QUERY\$1TEXT
<a name="SYS_QUERY_TEXT"></a>

使用 SYS\$1QUERY\$1TEXT 查看所有查询的查询文本。每行代表最多 4000 个字符的查询的查询文本（从序列号 0 开始）。当查询语句包含超过 4000 个字符时，通过增加每行的序列号来为该语句记录额外的行。此视图记录所有用户查询文本，例如 DDL、实用程序、Amazon Redshift 查询和仅限领导节点的查询。

SYS\$1QUERY\$1TEXT 对所有用户均可见。超级用户可以查看所有行；普通用户只能查看其自己的数据。有关更多信息，请参阅 [系统表和视图中的数据可见性](cm_chap_system-tables.md#c_visibility-of-data)。

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

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

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

以下查询返回了正在运行的查询和已排队的查询。

```
SELECT user_id, 
 query_id, 
 transaction_id, 
 session_id, start_time, 
 sequence, trim(text) as text from sys_query_text 
 ORDER BY sequence;
```

示例输出。

```
 user_id | query_id | transaction_id | session_id |        start_time          | sequence |                                                        text
--------+----------+-----------------+------------+----------------------------+----------+----------------------------------------------------------------------------------------------------------------------
   100  |     4    |       1396      | 1073750220 | 2023-04-28 16:44:55.887184 |     0    | SELECT trim(text) as text, sequence FROM sys_query_text WHERE query_id = pg_last_query_id() AND user_id > 1 AND start
_time > '2023-04-28 16:44:55.922705+00:00'::timestamp order by sequence;
```

以下查询返回已在数据库的组中授予或撤消的权限。

```
SELECT 
    SPLIT_PART(text, ' ', 1) as grantrevoke, 
    SPLIT_PART((SUBSTRING(text, STRPOS(UPPER(text), 'GROUP'))), ' ', 2) as group, 
    SPLIT_PART((SUBSTRING(text, STRPOS(UPPER(text), ' '))), 'ON', 1) as type, 
    SPLIT_PART((SUBSTRING(text, STRPOS(UPPER(text), 'ON'))), ' ', 2) || ' ' || SPLIT_PART((SUBSTRING(text, STRPOS(UPPER(text), 'ON'))), ' ', 3) as entity 
FROM SYS_QUERY_TEXT 
WHERE (text LIKE 'GRANT%' OR text LIKE 'REVOKE%') AND text LIKE '%GROUP%';
         
+-------------+----------+--------+----------+
| grantrevoke |  group   |  type  |  entity  |
+-------------+----------+--------+----------+
| GRANT       | bi_group | SELECT | TABLE t1 |
| GRANT       | bi_group | SELECT | TABLE t1 |
| GRANT       | bi_group | SELECT | TABLE t1 |
| GRANT       | bi_group | USAGE  | TABLE t1 |
| GRANT       | bi_group | SELECT | TABLE t1 |
| GRANT       | bi_group | SELECT | TABLE t1 |
+-------------+----------+--------+----------+
```