

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

# 使用 CTAS 和 INSERT INTO 來建立 Amazon Ion 資料表
<a name="ion-serde-using-ctas-and-insert-into-to-create-ion-tables"></a>

您可以在 Athena 中，使用 `CREATE TABLE AS SELECT` (CTAS) 和 `INSERT INTO` 陳述式將資料表中的資料複製或插入到 Amazon Ion 格式的新資料表中。

在 CTAS 查詢中，以 `WITH` 子句指定 `format='ION'`，如下列範例所示。

```
CREATE TABLE new_table
WITH (format='ION')
AS SELECT * from existing_table
```

依預設，Athena 將以 [Ion 二進位格式](https://amzn.github.io/ion-docs/docs/binary.html)序列化 Amazon Ion 結果，但您也可以使用文字格式。要使用文字格式，請以 CTAS `WITH` 子句指定 `ion_encoding = 'TEXT'`，如下列範例所示。

```
CREATE TABLE new_table
WITH (format='ION', ion_encoding = 'TEXT')
AS SELECT * from existing_table
```

如需有關 CTAS `WITH` 子句中的 Amazon Ion 特定屬性的詳細資訊，請參閱 [CTAS WITH 子句的 Amazon Ion 屬性](#ion-serde-ctas-with-clause-properties)。

## CTAS WITH 子句的 Amazon Ion 屬性
<a name="ion-serde-ctas-with-clause-properties"></a>

在 CTAS 查詢中，您可以使用 `WITH` 子句來指定 Amazon Ion 格式，並可選擇指定要使用的 Amazon Ion 編碼及/或寫入壓縮演算法。

**格式**  
您可以將 `ION` 關鍵字指定為 CTAS 查詢的 `WITH` 子句中的格式選項。在執行這項操作時，您建立的資料表將使用您為 `IonInputFormat` 指定的格式進行讀取，並以您為 `IonOutputFormat` 指定的格式序列化資料。  
以下範例指定 CTAS 查詢使用 Amazon Ion 格式。  

```
WITH (format='ION')
```

**ion\$1encoding**  
選用  
預設：`BINARY`  
值：`BINARY`、`TEXT`  
指定資料是以 Amazon Ion 二進位格式還是以 Amazon Ion 文字格式序列化。以下範例指定了 Amazon Ion 文字格式。  

```
WITH (format='ION', ion_encoding='TEXT')
```

**write\$1compression**  
選用  
預設：`GZIP`  
值：`GZIP`、`ZSTD`、`BZIP2`、`SNAPPY`、`NONE`  
指定用於壓縮輸出檔案的壓縮演算法。  
以下範例指定了 CTAS 查詢使用 [Zstandard](https://facebook.github.io/zstd/) 壓縮演算法以 Amazon Ion 格式寫入其輸出。  

```
WITH (format='ION', write_compression = 'ZSTD')       
```
如需有關在 Athena 中使用壓縮的資訊，請參閱[在 Athena 中使用壓縮](compression-formats.md)。

如需有關在 Athena 中的其他 CTAS 屬性，請參閱 [CTAS 資料表屬性](create-table-as.md#ctas-table-properties)。