ALTER EXTERNAL TABLE 範例 - Amazon Redshift

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

ALTER EXTERNAL TABLE 範例

下列範例使用位於美國東部 (維吉尼亞北部) 區域 (us-east-1) 的 Amazon S3 儲存貯體,以 AWS 區域 及範例針對 CREATE TABLE 建立的範例表格。如需如何搭配外部資料表使用分割區的詳細資訊,請參閱分割 Redshift Spectrum 外部資料表

以下範例會將 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_PART 資料表新增一個分割區。

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_PART 資料表新增三個分割區。

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_PART 以刪除具有 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');