

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

# ALTER EXTERNAL TABLE 示例
<a name="r_ALTER_TABLE_external-table"></a>

以下示例使用位于美国东部（弗吉尼亚州北部）区域（`us-east-1`）AWS 区域的 Amazon S3 存储桶，以及在 [示例](r_CREATE_EXTERNAL_TABLE_examples.md) 中为 CREATE TABLE 创建的示例表。有关如何将分区与外部表一起使用的更多信息，请参阅[对 Redshift Spectrum 外部表进行分区](c-spectrum-external-tables.md#c-spectrum-external-tables-partitioning)。

以下示例将 SPECTRUM.SALES 外部表的 numRows 表属性设置为 170000 行。

```
alter table spectrum.sales
set table properties ('numRows'='170000');
```

以下示例更改 SPECTRUM.SALES 外部表的位置。

```
alter table spectrum.sales
set location 's3://redshift-downloads/tickit/spectrum/sales/';
```

以下示例将 SPECTRUM.SALES 外部表的格式更改为 Parquet。

```
alter table spectrum.sales
set file format parquet;
```

以下示例为表 SPECTRUM.SALES\$1PART 添加一个分区。

```
alter table spectrum.sales_part
add if not exists partition(saledate='2008-01-01')
location 's3://redshift-downloads/tickit/spectrum/sales_partition/saledate=2008-01/';
```

以下示例为表 SPECTRUM.SALES\$1PART 添加三个分区。

```
alter table spectrum.sales_part add if not exists
partition(saledate='2008-01-01')
location 's3://redshift-downloads/tickit/spectrum/sales_partition/saledate=2008-01/'
partition(saledate='2008-02-01')
location 's3://redshift-downloads/tickit/spectrum/sales_partition/saledate=2008-02/'
partition(saledate='2008-03-01')
location 's3://redshift-downloads/tickit/spectrum/sales_partition/saledate=2008-03/';
```

以下示例修改 SPECTRUM.SALES\$1PART 以删除包含 `saledate='2008-01-01''` 的分区。

```
alter table spectrum.sales_part
drop partition(saledate='2008-01-01');
```

以下示例为包含 `saledate='2008-01-01'` 的分区设置新的 Amazon S3 路径。

```
alter table spectrum.sales_part
partition(saledate='2008-01-01')
set location 's3://redshift-downloads/tickit/spectrum/sales_partition/saledate=2008-01-01/';
```

以下示例将 `sales_date` 的名称更改为 `transaction_date`。

```
alter table spectrum.sales rename column sales_date to transaction_date;
```

以下示例将列映射设置为使用优化行列式 (ORC) 格式的外部表的位置映射。

```
alter table spectrum.orc_example
set table properties('orc.schema.resolution'='position');
```

以下示例将列映射设置为使用 ORC 格式的外部表的名称映射。

```
alter table spectrum.orc_example
set table properties('orc.schema.resolution'='name');
```