

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

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

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

下列範例使用位於美國東部 （維吉尼亞北部） 區域 (`us-east-1`) 的 Amazon S3 儲存貯體， AWS 區域 以及在 中[範例](r_CREATE_EXTERNAL_TABLE_examples.md)為 CREATE TABLE 建立的範例資料表。如需如何搭配外部資料表使用分割區的詳細資訊，請參閱 [分割 Redshift Spectrum 外部資料表](c-spectrum-external-tables.md#c-spectrum-external-tables-partitioning)。

以下範例會將 SPECTRUM.SALES 外部資料表的 numRows 資料表屬性設定為 170,000 個資料列。

```
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');
```