

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

# EXCLUDE column\$1list
<a name="r_EXCLUDE_list"></a>

EXCLUDE column\$1list 对从查询结果中排除的列进行命名。当只需从*宽* 表（包含许多列的表）中排除一部分列时，使用 EXCLUDE 选项会很有用。

**Topics**
+ [语法](#r_EXCLUDE_list-synopsis)
+ [参数](#r_EXCLUDE_list-parameters)
+ [示例](#r_EXCLUDE_list-examples)

## 语法
<a name="r_EXCLUDE_list-synopsis"></a>

```
EXCLUDE column_list
```

## 参数
<a name="r_EXCLUDE_list-parameters"></a>

 *column\$1list*   
查询引用的表中存在的一个或多个列名称的逗号分隔列表。*column\$1list* 可以选择用括号括起来。列名称的排除列表中仅支持列名称，而不支持表达式（例如 `upper(col1)`）或星号（\$1）。  

```
column-name, ... | ( column-name, ... )
```
例如：  

```
SELECT * EXCLUDE col1, col2 FROM tablea;
```

```
SELECT * EXCLUDE (col1, col2) FROM tablea;
```

## 示例
<a name="r_EXCLUDE_list-examples"></a>

下面的示例使用包含以下各列的 SALES 表：salesid、listid、sellerid、buyerid、eventid、dateid、qtysold、pricepaid、commission 和 saletime。有关 SALES 表的更多信息，请参阅[示例数据库](c_sampledb.md)。

以下示例返回 SALES 表中的行，但不包括 SALETIME 列。

```
SELECT * EXCLUDE saletime FROM sales;

salesid | listid  | sellerid | buyerid | eventid | dateid  | qtysold  | pricepaid  | commission
--------+---------+----------+---------+---------+---------+----------+------------+-----------
150314  | 173969  | 48680    | 816     | 8762    | 1827    | 2        | 688        | 103.2	
8325    | 8942    | 23600    | 1078    | 2557    | 1828    | 5        | 525        |  78.75	
46807   | 52711   | 34388    | 1047    | 2046    | 1828    | 2        | 482        |  72.3	
...
```

以下示例返回 SALES 表中的行，但不包括 QTYSOLD 和 SALETIME 列。

```
SELECT * EXCLUDE (qtysold, saletime) FROM sales;

salesid | listid  | sellerid | buyerid | eventid | dateid  | pricepaid  | commission
--------+---------+----------+---------+---------+---------+------------+-----------
150314  | 173969  | 48680    | 816     | 8762    | 1827    | 688        | 103.2	
8325    | 8942    | 23600    | 1078    | 2557    | 1828    | 525        |  78.75	
46807   | 52711   | 34388    | 1047    | 2046    | 1828    | 482        |  72.3	
...
```

以下示例创建了一个视图，该视图返回 SALES 表中的行，但不包括 SALETIME 列。

```
CREATE VIEW sales_view AS SELECT * EXCLUDE saletime FROM sales;
SELECT * FROM sales_view;

salesid | listid  | sellerid | buyerid | eventid | dateid  | qtysold  | pricepaid  | commission
--------+---------+----------+---------+---------+---------+----------+------------+-----------
150314  | 173969  | 48680    | 816     | 8762    | 1827    | 2        | 688        | 103.2	
8325    | 8942    | 23600    | 1078    | 2557    | 1828    | 5        | 525        |  78.75	
46807   | 52711   | 34388    | 1047    | 2046    | 1828    | 2        | 482        |  72.3	
...
```

以下示例仅选择未排除到临时表中的列。

```
SELECT * EXCLUDE saletime INTO TEMP temp_sales FROM sales;
SELECT * FROM temp_sales;

salesid | listid  | sellerid | buyerid | eventid | dateid  | qtysold  | pricepaid  | commission
--------+---------+----------+---------+---------+---------+----------+------------+-----------
150314  | 173969  | 48680    | 816     | 8762    | 1827    | 2        | 688        | 103.2	
8325    | 8942    | 23600    | 1078    | 2557    | 1828    | 5        | 525        |  78.75	
46807   | 52711   | 34388    | 1047    | 2046    | 1828    | 2        | 482        |  72.3	
...
```