

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

# DML 查詢、函數和運算子
<a name="dml-queries-functions-operators"></a>

Athena DML 查詢引擎通常支援 Trino 和 Presto 語法，並且自行對其進行了改進。Athena 不支援 Trino 或 Presto 的所有功能。如需詳細資訊，請參閱本節中特定陳述式的主題以及[考量和限制](other-notable-limitations.md)。如需有關函數資訊，請參閱 [Amazon Athena 中的函數](functions.md)。如需有關 Athena 引擎版本的資訊，請參閱[Athena 引擎版本控制](engine-versions.md)。

如需 DDL 陳述式的資訊，請參閱[DDL 陳述式](ddl-reference.md)。如需不支援的 DDL 陳述式之清單，請參閱[不支援的 DDL](unsupported-ddl.md)。

**Topics**
+ [SELECT](select.md)
+ [INSERT INTO](insert-into.md)
+ [VALUES](values-statement.md)
+ [DELETE](delete-statement.md)
+ [UPDATE](update-statement.md)
+ [合併為](merge-into-statement.md)
+ [OPTIMIZE](optimize-statement.md)
+ [VACUUM](vacuum-statement.md)
+ [EXPLAIN 和 EXPLAIN ANALYZE](athena-explain-statement.md)
+ [PREPARE](sql-prepare.md)
+ [UNLOAD](unload.md)
+ [函數](functions.md)
+ [使用支援的時區](athena-supported-time-zones.md)

# SELECT
<a name="select"></a>

從零個或多個資料表中擷取資料列。

**注意**  
本主題提供摘要資訊以供參考。關於使用 `SELECT` 和 SQL 語言的完整資訊已超出本文件的範圍。如需有關使用 Athena 特定 SQL 的資訊，請參閱[在 Amazon Athena 中進行 SQL 查詢的考量事項與限制](other-notable-limitations.md)和[在 Amazon Athena 中執行 SQL 查詢](querying-athena-tables.md)。如需在 Athena 建立資料庫、建立資料表和執行資料表 `SELECT` 查詢的範例，請參閱 [開始使用](getting-started.md)。

## 概要
<a name="synopsis"></a>

```
[ WITH with_query [, ...] ]
SELECT [ ALL | DISTINCT ] select_expression [, ...]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY [ ALL | DISTINCT ] grouping_element [, ...] ]
[ HAVING condition ]
[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]
[ ORDER BY expression [ ASC | DESC ] [ NULLS FIRST | NULLS LAST] [, ...] ]
[ OFFSET count [ ROW | ROWS ] ]
[ LIMIT [ count | ALL ] ]
```

**注意**  
SQL SELECT 陳述式中的保留字必須以雙引號括住。如需詳細資訊，請參閱[SQL SELECT 陳述式中要逸出的預留關鍵字](reserved-words.md#list-of-reserved-words-sql-select)。

## Parameters
<a name="select-parameters"></a>

**[ WITH with\$1query [, ....] ]**  
您可以使用 `WITH` 來展開巢狀查詢，或簡化子查詢。  
Athena 引擎版本 3 開始支援使用 `WITH` 子句建立遞迴查詢。最大遞歸深度為 10。  
`WITH` 子句位於查詢中的 `SELECT` 清單前面，可定義一或多個子查詢以用於 `SELECT` 查詢內。  
每個子查詢定義臨時資料表，類似於檢視定義，供您在 `FROM` 子句中參考。這些資料表只在查詢執行時才使用。  
`with_query` 語法是：  

```
subquery_table_name [ ( column_name [, ...] ) ] AS (subquery)
```
其中：  
+  `subquery_table_name` 是臨時資料表的唯一名稱，定義 `WITH` 子句子查詢的結果。每個 `subquery` 必須有可在 `FROM` 子句中參考的資料表名稱。
+  `column_name [, ...]` 是選用的輸出欄名稱清單。欄名稱的數目必須等於或少於 `subquery` 所定義的欄數。
+  `subquery` 是任何查詢陳述式。

**[ ALL \$1 DISTINCT ] select\$1expression**  
 `select_expression` 決定要選取的列。`select_expression` 可以使用下列其中一個格式：  

```
expression [ [ AS ] column_alias ] [, ...]
```

```
row_expression.* [ AS ( column_alias [, ...] ) ]
```

```
relation.*
```

```
*
```
+ `expression [ [ AS ] column_alias ]` 語法會指定輸出資料欄。選用的 `[AS] column_alias` 語法會指定要用於輸出中資料欄的自訂標題名稱。
+ 對於 `row_expression.* [ AS ( column_alias [, ...] ) ]`，`row_expression` 是資料類型 `ROW` 的任意表達式。資料列的欄位會定義要包含在結果中的輸出資料欄。
+ 對於 `relation.*`，`relation` 的資料欄會包含在結果中。此語法不允許使用資料欄別名。
+ 星號 `*` 會指定所有資料欄都會包含在結果集中。
+ 在結果集中，資料欄的順序與 select 表達式所指定的資料欄規範順序相同。如果 select 表達式傳回多個資料欄，則資料欄順序會遵循來源關係或資料列類型表達式中使用的順序。
+ 指定資料欄別名時，別名會覆寫預先存在的資料欄或資料列欄位名稱。如果 select 表達式沒有資料欄名稱，則輸出中會顯示零索引的匿名資料欄名稱 (`_col0`、`_col1`、`_col2, ...`)。
+  預設值為 `ALL`。`ALL` 使用與省略不用都一樣；所有欄的所有列都會選取，重複的列也會保留。
+ 當欄包含重複值時，可使用 `DISTINCT` 只傳回獨特值。

**FROM from\$1item [, ...]**  
指出查詢的輸入，其中 `from_item` 可以是檢視、聯結建構或子查詢，如下所示。  
`from_item` 可以是以下任一項：  
+  `table_name [ [ AS ] alias [ (column_alias [, ...]) ] ]` 

  其中，`table_name` 是從中選取列的目標表格的名稱，`alias` 是提供給 `SELECT` 陳述式輸出的名稱，`column_alias` 為指定的 `alias` 定義欄。
 **-或-**   
+  `join_type from_item [ ON join_condition | USING ( join_column [, ...] ) ]` 

  其中 `join_type` 是以下其中一個：
  +  `[ INNER ] JOIN` 
  +  `LEFT [ OUTER ] JOIN` 
  +  `RIGHT [ OUTER ] JOIN` 
  +  `FULL [ OUTER ] JOIN` 
  +  `CROSS JOIN` 
  +  `ON join_condition | USING (join_column [, ...])` 其中，使用 `join_condition` 可讓您指定多個資料表中聯結索引鍵的欄名稱，而使用 `join_column` 之前，兩個資料表中必須都有 `join_column`。

**[ WHERE condition ]**  
根據您指定的 `condition` 篩選結果，其中 `condition` 通常具有以下語法。  

```
column_name operator value [[[AND | OR] column_name operator value] ...]
```
*operator* 可以是其中一個比較子：`=`、`>`、`<`、`>=`、`<=`、`<>`、`!=`。  
下面的子查詢表達式也可以用在 `WHERE` 子句中。  
+ `[NOT] BETWEEN integer_A AND integer_B` – 指定兩個整數之間的範圍，如下列範例所示。如果資料欄資料類型是 `varchar`，則必須先將資料欄轉換為整數。

  ```
  SELECT DISTINCT processid FROM "webdata"."impressions"
  WHERE cast(processid as int) BETWEEN 1500 and 1800
  ORDER BY processid
  ```
+ `[NOT] LIKE value` – 搜尋指定的模式。使用百分比符號 (`%`) 作為萬用字元，如下列範例所示。

  ```
  SELECT * FROM "webdata"."impressions"
  WHERE referrer LIKE '%.org'
  ```
+ `[NOT] IN (value[, value[, ...])` – 指定資料欄可能的值之清單，如下列範例所示。

  ```
  SELECT * FROM "webdata"."impressions"
  WHERE referrer IN ('example.com','example.net','example.org')
  ```

**[ GROUP BY [ ALL \$1 DISTINCT ] grouping\$1expressions [, ...] ]**  
將 `SELECT` 陳述式的輸出分割成具有相符值的列。  
 `ALL` 和 `DISTINCT` 指定重複的分組集是否各產生相異的輸出列。如果省略，會採用 `ALL`。  
`grouping_expressions` 可讓您執行複雜的分組操作。您可以使用複雜的分組操作來執行需要對單一查詢中的多組資料欄進行彙總的分析。  
`grouping_expressions` 元素可以是任何函數，例如對輸入資料欄執行的 `SUM`、`AVG` 或 `COUNT`。  
`GROUP BY` 表達式可依未出現在 `SELECT` 陳述式輸出中的輸入欄名稱，將輸出分組。  
所有輸出表達式必須是彙總函數，或存在於 `GROUP BY` 子句中的欄。  
您可以使用單一查詢來執行需要彙總多個欄集的分析。  
Athena 支援使用 `GROUPING SETS`、`CUBE` 和 `ROLLUP` 的複雜彙總。`GROUP BY GROUPING SETS` 指定要分組的多個資料欄清單。`GROUP BY CUBE` 會針對一組給定的資料欄，產生所有可能的分組集。`GROUP BY ROLLUP` 會針對一組給定的資料欄，產生所有可能的小計。複雜的分組操作不支援對由輸入資料欄組成的表達式進行分組。只允許資料欄名稱。  
您通常可以使用 `UNION ALL` 來達到與這些 `GROUP BY` 操作相同的結果，但使用 `GROUP BY` 的查詢好處是只讀取資料一次，而 `UNION ALL` 會讀取基礎資料三次，而且當資料來源易於變更時，可能會產生不一致的結果。

**[ HAVING condition ]**  
與彙總函數和 `GROUP BY` 子句一起使用。控制要選取哪些群組，排除不符合 `condition` 的群組。計算群組和彙總之後會執行此篩選。

**[ \$1 UNION \$1 INTERSECT \$1 EXCEPT \$1 [ ALL \$1 DISTINCT ] union\$1query] ]**  
`UNION`、`INTERSECT` 和 `EXCEPT` 將一個以上的 `SELECT` 陳述式的結果結合為單一查詢。`ALL` 或 `DISTINCT` 控制最終結果集包含的資料行的唯一性。  
`UNION` 將第一個查詢產生的資料行與第二個查詢產生的資料行組合起來。為消除重複項，`UNION` 構建了一個消耗記憶體的雜湊資料表。為了更好的性能，如果您的查詢不需要消除重複項，則請考慮使用 `UNION ALL`。除非您使用括號來明確定義處理順序，否則多個 `UNION` 子句是由左向右處理。  
`INTERSECT` 只傳回存在於第一個和第二個查詢之結果中的資料行。  
`EXCEPT` 傳回第一個查詢之結果的資料行，不包括第二個查詢找到的資料行。  
`ALL` 會包含所有資料行，即使資料行都相同也一樣。  
`DISTINCT` 只會讓唯一的資料行包含在合併結果集中。

**[ ORDER BY expression [ ASC \$1 DESC ] [ NULLS FIRST \$1 NULLS LAST] [, ...] ]**  
依一或多個輸出 `expression` 排序結果集。  
當子句包含多個表達式時，結果集會根據第一個 `expression` 排序。然後，第二個 `expression` 套用的列有來自第一個表達式的相符值，以此類推。  
每個 `expression` 可以指定 `SELECT` 的輸出欄，或依位置指定輸出欄的序數 (從 1 開始)。  
`ORDER BY` 是在任何 `GROUP BY` 或 `HAVING` 子句之後當作最後一個步驟來評估。`ASC` 和 `DESC` 決定結果依遞增或遞減順序來排序。依預設，排序順序為遞增排序 (`ASC`)。無論是遞增或遞減排序，預設空值排序是 `NULLS LAST`。

**[ OFFSET count [ ROW \$1 ROWS ] ]**  
使用 `OFFSET` 子句來捨棄結果集中的數個前導列。如果 `ORDER BY` 子句存在時，`OFFSET` 子句會根據排序的結果集進行評估，並且該集會在跳過的資料列遭到捨棄後保持排序。如果查詢沒有 `ORDER BY` 子句，則可以任意捨棄資料列。如果 `OFFSET` 指定的計數等於或超過結果集的大小，則最終結果為空白。

**LIMIT [ count \$1 ALL ]**  
將結果集的列數限制為 `count`。`LIMIT ALL` 和省略 `LIMIT` 子句的效果相同。如果查詢沒有 `ORDER BY` 子句，則結果是任意順序。

**TABLESAMPLE [ BERNOULLI \$1 SYSTEM ] (percentage)**  
根據取樣方法從資料表中選擇列的選用運算子。  
 `BERNOULLI` 以機率 `percentage` 選取要放入資料表樣本中的每一列。將會掃描資料表的所有實體區塊，並根據範本 `percentage` 和執行時間計算的隨機值之間的比較，略過特定的資料行。  
使用 `SYSTEM` 時，資料表會分割為邏輯的資料區段，並以此精細程式來取樣資料表。  
將會選取特定區段的所有資料行，或根據取樣 `percentage` 和執行時間計算的隨機值之間的比較，略過區段。`SYSTEM` 取樣依賴連接器。這個方法不保證獨立取樣機率。

**[ UNNEST (array\$1or\$1map) [WITH ORDINALITY] ]**  
將陣列或映射展開成關係。陣列會展開成單一欄。映射會展開成兩欄 (*索引鍵*、*值*)。  
您可以使用 `UNNEST` 搭配多個參數，以展開成多個欄，且列數與最高基數引數相等。  
其他欄以空值填補。  
`WITH ORDINALITY` 子句會將基數欄新增至尾端。  
 `UNNEST` 通常與 `JOIN` 一起使用，且可以參考 `JOIN` 左側關係中的欄。

## 在 Amazon S3 中取得來源資料的檔案位置
<a name="select-path"></a>

若要查看資料表資料行中資料的 Amazon S3 檔案位置，可以使用 `SELECT` 查詢中的 `"$path"`，如下列範例所示：

```
SELECT "$path" FROM "my_database"."my_table" WHERE year=2019;
```

此舉會傳回如下所示的結果：

```
s3://amzn-s3-demo-bucket/datasets_mytable/year=2019/data_file1.json
```

若要傳回資料表中資料的 S3 檔案名稱路徑經排序的單一清單，可以使用 `SELECT DISTINCT` 和 `ORDER BY`，如下範例所示。

```
SELECT DISTINCT "$path" AS data_source_file
FROM sampledb.elb_logs
ORDER By data_source_file ASC
```

若要僅傳回沒有路徑的檔案名稱，則可將 `"$path"` 作為參數傳遞給 `regexp_extract` 函數，如下列範例所示。

```
SELECT DISTINCT regexp_extract("$path", '[^/]+$') AS data_source_file
FROM sampledb.elb_logs
ORDER By data_source_file ASC
```

若要從特定檔案傳回資料，請在 `WHERE` 子句中指定檔案，如下列範例所示。

```
SELECT *,"$path" FROM my_database.my_table WHERE "$path" = 's3://amzn-s3-demo-bucket/my_table/my_partition/file-01.csv'
```

如需詳細資訊和範例，請參閱知識中心文章：[如何查看 Athena 資料表中某資料行的 Amazon S3 來源檔案？](https://aws.amazon.com/premiumsupport/knowledge-center/find-s3-source-file-athena-table-row/)。

**注意**  
在 Athena 中，檢視不支援 Hive 或 Iceberg 隱藏的中繼資料欄 `$bucket`、`$file_modified_time`、`$file_size` 和 `$partition`。

## 逸出單引號
<a name="select-escaping"></a>

 若要逸出單引號，請在它前面加上另一個單引號，如下列範例所示。請勿將此與雙引號混淆。

```
Select 'O''Reilly'
```

**結果**  
`O'Reilly`

## 其他資源
<a name="select-additional-resources"></a>

如需有關使用 Athena 中 `SELECT` 陳述式的詳細資訊，請參閱以下資源。


| 如需有關以下內容的資訊 | 參閱以下資源 | 
| --- | --- | 
| 在 Athena 中執行查詢 | [在 Amazon Athena 中執行 SQL 查詢](querying-athena-tables.md) | 
| 使用 SELECT 建立資料表 | [從查詢結果建立資料表 (CTAS)](ctas.md) | 
| 將一個 SELECT 查詢的資料插入其他資料表 | [INSERT INTO](insert-into.md) | 
| 使用 SELECT 陳述式中內建的函數 | [Amazon Athena 中的函數](functions.md) | 
| 使用 SELECT 陳述式中使用者定義函數 | [利用使用者定義函式進行查詢](querying-udf.md) | 
| 查詢資料目錄中繼資料 | [查詢 AWS Glue Data Catalog](querying-glue-catalog.md) | 

# INSERT INTO
<a name="insert-into"></a>

根據來源資料表上執行的 `SELECT` 查詢陳述式，或根據作為該陳述式的一部分提供的一組 `VALUES`，將新資料行插入目標資料表。當來源資料表以某一格式 (例如 CSV 或 JSON) 的基礎資料為基礎時，而目標資料表以另一種格式 (例如 Parquet 或 ORC) 為基礎，則您可以使用 `INSERT INTO` 查詢，將選取的資料轉換為目標資料表的格式。

## 考量和限制
<a name="insert-into-limitations"></a>

搭配 Athena 使用 `INSERT` 查詢時，請考慮以下情況：
+ 在包含於 Amazon S3 中加密的基礎資料的資料表上執行 `INSERT` 查詢時，`INSERT` 查詢寫入的輸出檔案依預設不會加密。如果您要插入具有加密資料的資料表，建議您加密 `INSERT` 查詢結果。

  如需使用主控台加密查詢結果的詳細資訊，請參閱[加密 Amazon S3 中存放的 Athena 查詢結果](encrypting-query-results-stored-in-s3.md)。若要使用 AWS CLI 或 Athena API 啟用加密，請使用 [StartQueryExecution](https://docs.aws.amazon.com/athena/latest/APIReference/API_StartQueryExecution.html) 動作的`EncryptionConfiguration`屬性，根據您的需求指定 Amazon S3 加密選項。
+ 對於 `INSERT INTO` 陳述式，預期的儲存貯體擁有者設定不適用於 Amazon S3 中的目的地資料表位置。預期的儲存貯體擁有者設定僅適用於您為 Athena 查詢結果指定的 Amazon S3 輸出位置。如需詳細資訊，請參閱[使用 Athena 主控台指定查詢結果位置](query-results-specify-location-console.md)。
+ 如需 ACID 合規 `INSERT INTO` 陳述式，則請參閱 [更新 Iceberg 資料表資料](querying-iceberg-updating-iceberg-table-data.md) 的 `INSERT INTO` 一節。

### 支援的格式和 SerDes
<a name="insert-into-supported-formats"></a>

您可以在使用下列格式和 SerDes 資料建立的資料表上，執行 `INSERT` 查詢。


| 資料格式 | SerDe | 
| --- | --- | 
|  Avro  |  org.apache.hadoop.hive.serde2.avro.AvroSerDe  | 
| Ion | com.amazon.ionhiveserde.IonHiveSerDe | 
|  JSON  |  org.apache.hive.hcatalog.data.JsonSerDe  | 
|  ORC  |  org.apache.hadoop.hive.ql.io.orc.OrcSerde  | 
|  Parquet  |  org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe  | 
|  文字檔案  |  org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe  支援 TSV 和自訂分隔檔案。   | 
| CSV | org.apache.hadoop.hive.serde2.OpenCSVSerde 僅字串類型支援寫入。在 Athena 中，您無法寫入 Glue 結構描述中包含非字串類型的任何資料表。如需詳細資訊，請參閱 [CSV SerDe](csv-serde.md#csv-serde-opencsvserde-considerations-non-string)。  | 

### 不支援分區資料表
<a name="insert-into-bucketed-tables-not-supported"></a>

在分區資料表上不支援 `INSERT INTO`。如需詳細資訊，請參閱[使用分割和歸納](ctas-partitioning-and-bucketing.md)。

### 不支援聯合查詢
<a name="insert-into-federated-queries-not-supported"></a>

`INSERT INTO` 不支援聯合查詢。嘗試執行這項操作可能會產生錯誤訊息：外部目錄目前不支援此操作。如需聯合查詢的詳細資訊，請參閱[使用 Amazon Athena 聯合查詢](federated-queries.md)。

### 分割
<a name="insert-into-limitations-partitioning"></a>

搭配 `INSERT INTO` 或 `CREATE TABLE AS SELECT` 查詢使用分割區時，請將本章節的幾個重點納入考量。

#### 限制
<a name="insert-into-partition-limits"></a>

`INSERT INTO` 陳述式支援最多將 100 個分割區寫入目標資料表。如果您在分割區超過 100 個的資料表上執行 `SELECT` 子句，除非 `SELECT` 查詢限制在 100 個分割區或更少，否則查詢會失敗。

如需解決此限制的相關資訊，請參閱[使用 CTAS 和 INSERT INTO 來解決 100 個分割區限制](ctas-insert-into.md)。

#### 資料欄排序
<a name="insert-into-partition-detection"></a>

`INSERT INTO` 或 `CREATE TABLE AS SELECT` 陳述式會預期分割的資料欄為 `SELECT` 陳述式中投影資料欄清單的最後一個資料欄。

如果來源資料表未經分割，或與目標資料表相比在不同的資料欄上分割，則如 `INSERT INTO destination_table SELECT * FROM source_table` 的查詢會將來源資料表中的最後一個資料欄的值，認定為目標資料表中的分割區資料欄的值。嘗試從未分割的資料表建立分割的資料表時，請注意以上提醒。

#### Resources
<a name="insert-into-partition-resources"></a>

如需有關搭配分割使用 `INSERT INTO` 的詳細資料，請參閱以下資源。
+ 如需將分割的資料插入分割的資料表，請參閱[使用 CTAS 和 INSERT INTO 來解決 100 個分割區限制](ctas-insert-into.md)。
+ 如需將未分割的資料插入分割的資料表，請參閱[使用 CTAS 和 INSERT INTO 以進行 ETL 和資料分析](ctas-insert-into-etl.md)。

### 寫入 Amazon S3 的檔案
<a name="insert-into-files-written-to-s3"></a>

`INSERT` 命令執行之後，Athena 會將檔案寫入 Amazon S3 中的來源資料位置。每個 `INSERT` 操作都會建立新的檔案，而不是附加到現有的檔案。檔案位置取決於資料表和 `SELECT` 查詢的結構 (若有)。Athena 會為每個 `INSERT` 查詢生成一個資訊清單檔案。資訊清單會追蹤查詢寫入的檔案。它會儲存到 Amazon S3 中的 Athena 查詢結果位置。如需詳細資訊，請參閱[識別查詢輸出檔案](querying-finding-output-files.md#querying-identifying-output-files)。

### 避免高度交易更新
<a name="insert-into-transactional-caveat"></a>

當您使用 `INSERT INTO` 將資料列新增至 Amazon S3 中的資料表時，Athena 不會重寫或修改現有檔案。相反地，它會將這些資料列寫入一或多個新檔案中。由於資料表[擁有許多小型檔案，進而導致查詢效能降低](performance-tuning-data-optimization-techniques.md#performance-tuning-avoid-having-too-many-files)，以及寫入和讀取操作 (例如 `PutObject` 和 `GetObject`) 會導致 Amazon S3 的成本提高，因此使用 `INSERT INTO` 時請考慮下列選項：
+ 對於較大的資料列批次，降低執行 `INSERT INTO` 操作的頻率。
+ 對於大型資料擷取量，請考慮使用 [Amazon Data Firehose](https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html) 之類的服務。
+ 完全避免使用 `INSERT INTO`。相反地，請將資料列累積到較大的檔案中，然後直接上傳至 Amazon S3，其中 Athena 可以在其中查詢這些資料。

### 尋找孤立檔案
<a name="insert-into-files-partial-data"></a>

如果 `CTAS` 或 `INSERT INTO` 陳述式失敗，孤立的資料可以留在資料位置，並且可能會在後續查詢中讀取。若要尋找孤立檔案以進行檢測或刪除，您可以使用 Athena 提供的資料資訊清單檔案來追蹤要寫入的檔案清單。如需詳細資訊，請參閱[識別查詢輸出檔案](querying-finding-output-files.md#querying-identifying-output-files)和 [DataManifestLocation](https://docs.aws.amazon.com/athena/latest/APIReference/API_QueryExecutionStatistics.html#athena-Type-QueryExecutionStatistics-DataManifestLocation)。

## INSERT INTO...SELECT
<a name="insert-into-select"></a>

指定在一個資料表上執行的查詢：`source_table`，這會決定要插入第二個資料表的資料列：`destination_table`。如果 `SELECT` 查詢指定 `source_table` 中的資料欄，則該資料欄必須精確地符合 `destination_table` 中的資料欄。

如需 `SELECT` 查詢的詳細資訊，請參閱[SELECT](select.md)。

### 概要
<a name="insert-into-select-synopsis"></a>

```
INSERT INTO destination_table 
SELECT select_query 
FROM source_table_or_view
```

### 範例
<a name="insert-into-select-examples"></a>

選取 `vancouver_pageviews` 資料表中的所有列，並將其插入 `canada_pageviews` 資料表：

```
INSERT INTO canada_pageviews 
SELECT * 
FROM vancouver_pageviews;
```

僅選取 `vancouver_pageviews` 資料表中的列，其中 `date` 資料欄有介於 `2019-07-01` 到 `2019-07-31` 間的值，然後將其插入 `canada_july_pageviews`：

```
INSERT INTO canada_july_pageviews
SELECT *
FROM vancouver_pageviews
WHERE date
    BETWEEN date '2019-07-01'
        AND '2019-07-31';
```

請僅從 `country` 資料欄中 `usa` 的值選取 `cities_world` 資料表中 `city` 與 `state` 欄內的值，並將其插入 `cities_usa` 資料表中的 `city` 和 `state` 欄：

```
INSERT INTO cities_usa (city,state)
SELECT city,state
FROM cities_world
    WHERE country='usa'
```

## INSERT INTO... VALUES
<a name="insert-into-values"></a>

透過指定資料欄和值，將資料列插入現有的資料表。指定的資料欄和相關聯的資料類型必須精確地符合目標資料表中的資料欄和資料類型。

**重要**  
我們不建議使用 `VALUES` 插入資料行，因為 Athena 會為每個 `INSERT` 操作產生檔案。這可能會導致建立許多小型檔案，並降低資料表的查詢效能。若要識別 `INSERT` 查詢建立的檔案，請檢查資料資訊清單檔案。如需詳細資訊，請參閱[使用查詢結果和近期查詢](querying.md)。

### 概要
<a name="insert-into-values-synopsis"></a>

```
INSERT INTO destination_table [(col1,col2,...)] 
VALUES (col1value,col2value,...)[,
       (col1value,col2value,...)][,
       ...]
```

### 範例
<a name="insert-into-values-examples"></a>

在下列範例中，城市資料表有三個資料欄：`id`、`city`、`state`、`state_motto`。`id` 資料欄的類型是 `INT`，而其他所有欄的類型都是 `VARCHAR`。

將單一列插入 `cities` 資料表，並指定所有資料欄值：

```
INSERT INTO cities 
VALUES (1,'Lansing','MI','Si quaeris peninsulam amoenam circumspice')
```

在 `cities` 資料表中插入兩列：

```
INSERT INTO cities 
VALUES (1,'Lansing','MI','Si quaeris peninsulam amoenam circumspice'),
       (3,'Boise','ID','Esto perpetua')
```

# VALUES
<a name="values-statement"></a>

建立常值內嵌資料表。資料表可以是匿名的，或者您也可以使用 `AS` 子句來指定資料表名稱、資料欄名稱或兩者兼具。

## 概要
<a name="values-statement-synopsis"></a>

```
VALUES row [, ...]
```

## Parameters
<a name="values-statement-parameters"></a>

**資料列**  
`row` 參數可以是單一表達式，也可以是 `( column_expression [, ...] )`。

## 範例
<a name="values-statement-examples"></a>

傳回具有一個資料欄和三個資料列的資料表：

```
VALUES 1, 2, 3
```

傳回具有兩個資料欄和三個資料列的資料表：

```
VALUES
    (1, 'a'),
    (2, 'b'),
    (3, 'c')
```

傳回具有資料欄 `id` 和 `name` 的資料表：

```
SELECT * FROM (
    VALUES
        (1, 'a'),
        (2, 'b'),
        (3, 'c')
) AS t (id, name)
```

使用資料列 `id` 和 `name`，建立名為 `customers` 的資料表：

```
CREATE TABLE customers AS
SELECT * FROM (
    VALUES
        (1, 'a'),
        (2, 'b'),
        (3, 'c')
) AS t (id, name)
```

## 另請參閱
<a name="values-statement-see-also"></a>

[INSERT INTO... VALUES](insert-into.md#insert-into-values)

# DELETE
<a name="delete-statement"></a>

刪除 Apache Iceberg 資料表中的資料列。`DELETE` 是交易型的並且僅由 Apache Iceberg 資料表支援。

## 概要
<a name="delete-statement-synopsis"></a>

若要刪除 Iceberg 資料表中的資料列，請使用下列語法。

```
DELETE FROM [db_name.]table_name [WHERE predicate]
```

如需詳細資訊和範例，請參閱 [更新 Iceberg 資料表資料](querying-iceberg-updating-iceberg-table-data.md) 中的 `DELETE` 一節。

# UPDATE
<a name="update-statement"></a>

更新 Apache Iceberg 資料表中的資料列。`UPDATE` 是交易型的並且僅由 Apache Iceberg 資料表支援。該陳述式僅適用於現有資料列，且無法用於插入或附加資料列。

## 概要
<a name="update-statement-synopsis"></a>

若要更新 Iceberg 資料表中的資料列，請使用下列語法。

```
UPDATE [db_name.]table_name SET xx=yy[,...] [WHERE predicate]
```

如需詳細資訊和範例，請參閱 [更新 Iceberg 資料表資料](querying-iceberg-updating-iceberg-table-data.md) 中的 `UPDATE` 一節。

# 合併為
<a name="merge-into-statement"></a>

有條件地更新、刪除資料列或將其插入至 Apache Iceberg 資料表。單一陳述式可以組合更新、刪除和插入動作。

**注意**  
`MERGE INTO` 是交易型的並且僅由 Athena 引擎版本 3 中的 Apache Iceberg 資料表支援。

## 概要
<a name="merge-into-statement-synopsis"></a>

若要有條件地更新、刪除或插入 Iceberg 資料表中的資料列，請使用下列語法。

```
MERGE INTO target_table [ [ AS ]  target_alias ]
USING { source_table | query } [ [ AS ] source_alias ]
ON search_condition
when_clause [...]
```

*when\$1clause* 是下列其中一項：

```
WHEN MATCHED [ AND condition ]
    THEN DELETE
```

```
WHEN MATCHED [ AND condition ]
    THEN UPDATE SET ( column = expression [, ...] )
```

```
WHEN NOT MATCHED [ AND condition ]
    THEN INSERT (column_name[, column_name ...]) VALUES (expression, ...)
```

`MERGE` 支援具有不同 `MATCHED` 條件之任意數量的 `WHEN` 子句。條件子句會在由 `MATCHED` 狀態和符合條件選取的第一個 `WHEN` 子句中執行 `DELETE`、`UPDATE` 或 `INSERT` 運算。

針對每個來源資料列，會依序處理 `WHEN` 子句。只會執行第一個相符的 `WHEN` 子句。其餘子句會遭到忽略。當單一目標資料表資料列與多個來源資料列相符時，就會引起使用者錯誤。

如果來源資料列不與任何 `WHEN` 子句相符且沒有 `WHEN NOT MATCHED` 子句，則會忽略來源資料列。

在具有 `UPDATE` 運算的 `WHEN` 子句中，資料欄值表達式可以指代目標或來源的任何欄位。若是 `NOT MATCHED`，`INSERT` 表達式可以指代來源的任何欄位。

**範例**  
下列範例會將第二個資料表中的資料列合併至第一個資料表 (如果第一個資料表中不存在資料列)。請注意，`VALUES` 子句中列出的資料欄必須加上來源資料表別名的字首。`INSERT` 子句中列出的目標資料欄*不*得使用字首。

```
MERGE INTO iceberg_table_sample as ice1
USING iceberg2_table_sample as ice2
ON ice1.col1 = ice2.col1
WHEN NOT MATCHED 
THEN INSERT (col1)
      VALUES (ice2.col1)
```

如需更多 `MERGE INTO` 範例，請參閱 [更新 Iceberg 資料表資料](querying-iceberg-updating-iceberg-table-data.md)。

# OPTIMIZE
<a name="optimize-statement"></a>

根據相關刪除檔案的大小和數量，將資料檔案重寫成更好的版面配置，進而最佳化 Apache Iceberg 資料表中的列。

**注意**  
`OPTIMIZE` 是交易型的並且僅由 Apache Iceberg 資料表支援。

## 語法
<a name="optimize-statement-syntax"></a>

以下語法摘要說明最佳化處理 Iceberg 資料表的方式。

```
OPTIMIZE [db_name.]table_name REWRITE DATA USING BIN_PACK
  [WHERE predicate]
```

**注意**  
`WHERE` 子句*述詞*中只允許分割區資料欄。指定非分割區資料欄會導致查詢失敗。

壓縮動作按重寫過程中掃描的資料量計費。`REWRITE DATA` 動作使用述詞來選擇包含對應資料列的檔案。如果檔案中的任何資料列與述詞相對應，則會選擇該檔案進行最佳化處理。因此，為了控制壓縮時包含的文件數量，請指定 `WHERE` 子句。

## 設定壓縮屬性
<a name="optimize-statement-configuring-compaction-properties"></a>

為了控制要選擇進行壓縮的檔案大小以及壓縮後產生的檔案大小，請使用資料表屬性參數。您可以使用 [ALTER TABLE SET TBLPROPERTIES](querying-iceberg-alter-table-set-properties.md) 命令來設定相關的[資料表屬性](querying-iceberg-creating-tables.md#querying-iceberg-table-properties)。

## 其他資源
<a name="optimize-statement-additional-resources"></a>

[最佳化 Iceberg 資料表](querying-iceberg-data-optimization.md)

# VACUUM
<a name="vacuum-statement"></a>

`VACUUM` 陳述式會執行[快照過期](https://iceberg.apache.org/docs/latest/spark-procedures/#expire_snapshots)和[孤立檔案移除](https://iceberg.apache.org/docs/latest/spark-procedures/#remove_orphan_files)，進而在 Apache Iceberg 資料表上執行資料表維護。

**注意**  
`VACUUM` 是交易型的並且僅由 Athena 引擎版本 3 中的 Apache Iceberg 資料表支援。

`VACUUM` 陳述式會減少儲存消耗，進而最佳化 Iceberg 資料表。如需有關使用 `VACUUM` 的詳細資訊，請參閱 [最佳化 Iceberg 資料表](querying-iceberg-data-optimization.md)。請注意，由於 `VACUUM` 陳述式會對 Amazon S3 進行 API 呼叫，向 Amazon S3 發出相關請求需支付費用。

**警告**  
如果您執行快照過期操作，則無法再回溯至過期的快照。

## 概要
<a name="vacuum-statement-synopsis"></a>

若要移除 Iceberg 資料表中不再需要的資料檔案，請使用下列語法。

```
VACUUM [database_name.]target_table
```
+ `VACUUM` 預期 Iceberg 資料位於 Amazon S3 資料夾中，而非 Amazon S3 儲存貯體中。例如，如果您的 Iceberg 資料位於 `s3://amzn-s3-demo-bucket`/ 而非 `s3://amzn-s3-demo-bucket/myicebergfolder/`，則 `VACUUM` 陳述式會失敗，並顯示錯誤訊息 GENERIC\$1INTERNAL\$1ERROR：檔案系統位置中缺少路徑：`s3://amzn-s3-demo-bucket`。
+ 若要讓 `VACUUM` 能夠刪除資料檔案，您的查詢執行角色必須擁有對 Iceberg 資料表、中繼資料、快照和資料檔案所在儲存貯體的 `s3:DeleteObject` 許可。如果許可不存在，則 `VACUUM` 查詢會成功，但檔案不會刪除。
+ 若要在名稱以底線開頭 (例如 `_mytable`) 的資料表上執行 `VACUUM`，請以反引號括住資料表名稱，如下列範例所示。如果在資料表名稱前加上資料庫名稱作為字首，請勿以反引號括住資料庫名稱。請注意，雙引號不能取代反引號。

  此行為專屬於 `VACUUM`。對於以底線開頭的資料表名稱，`CREATE` 和 `INSERT INTO` 陳述式不需要反引號。

  ```
  VACUUM `_mytable`
  VACUUM my_database.`_mytable`
  ```

## 執行的操作
<a name="vacuum-statement-operations-performed"></a>

`VACUUM` 執行以下操作：
+ 移除早於 `vacuum_max_snapshot_age_seconds` 資料表屬性指定之時間的快照。依預設，此屬性已設為 432000 秒 (5 天)。
+ 移除不在保留期間內且超過 `vacuum_min_snapshots_to_keep` 資料表屬性所指定數目的快照。預設為 1。

  您可以在 `CREATE TABLE` 陳述式中指定這些資料表屬性。建立資料表之後，您就可以使用 [ALTER TABLE SET TBLPROPERTIES](querying-iceberg-alter-table-set-properties.md) 陳述式來進行更新。
+ 移除任何因為快照移除而無法取得的中繼資料和資料檔案。您可以設定 `vacuum_max_metadata_files_to_keep` 資料表屬性，進而設定要保留的舊中繼資料檔案數目。預設值為 100.
+ 移除早於 `vacuum_max_snapshot_age_seconds` 資料表屬性中指定之時間的孤立檔案。孤立檔案是資料表的資料目錄中不屬於資料表狀態的檔案。

如需有關在 Athena 中建立和管理 Apache Iceberg 資料表的詳細資訊，則請參閱 [建立 Iceberg 資料表](querying-iceberg-creating-tables.md) 和 [管理 Iceberg 資料表](querying-iceberg-managing-tables.md)。

# 在 Athena 使用 EXPLAIN 和 EXPLAIN ANALYZE
<a name="athena-explain-statement"></a>

`EXPLAIN` 陳述式會顯示指定 SQL 陳述式的邏輯或分散式執行計劃，或驗證 SQL 陳述式。您可以以文字格式或資料格式輸出結果，以便轉譯成圖形。

**注意**  
您可以在 Athena 主控台中檢視查詢的邏輯和分散式計劃的圖形呈現，無需使用 `EXPLAIN` 語法。如需詳細資訊，請參閱[檢視 SQL 查詢的執行計畫](query-plans.md)。

`EXPLAIN ANALYZE` 陳述式會顯示指定 SQL 陳述式的分散式執行計劃，以及 SQL 查詢中每個操作的運算成本。您可以將結果輸出為文字或 JSON 格式。

## 考量和限制
<a name="athena-explain-statement-considerations-and-limitations"></a>

在 Athena 的 `EXPLAIN` 和 `EXPLAIN ANALYZE` 陳述式有下列限制。
+ `EXPLAIN` 查詢不會掃描任何資料，因此 Athena 不會為此收取費用。然而，由於 `EXPLAIN` 查詢會呼叫 AWS Glue 來擷取資料表中繼資料，如果呼叫超過 [Glue 免費方案限制](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Categories=categories%23analytics&all-free-tier.q=glue&all-free-tier.q_operator=AND)的次數，則會從 Glue 收取費用。
+ 因為已執行 `EXPLAIN ANALYZE` 查詢，它們會掃描資料，並且 Athena 會針對掃描的資料量收取費用。
+ 在 Lake Formation 中定義的資料列或儲存格篩選資訊及查詢統計資料資訊未在 `EXPLAIN` 和 `EXPLAIN ANALYZE` 的輸出中顯示。

## EXPLAIN 語法
<a name="athena-explain-statement-syntax-athena-engine-version-2"></a>

```
EXPLAIN [ ( option [, ...]) ] statement
```

*option* 可為下列項目之一：

```
FORMAT { TEXT | GRAPHVIZ | JSON }
TYPE { LOGICAL | DISTRIBUTED | VALIDATE | IO }
```

如果未指定 `FORMAT` 選項，則輸出預設為 `TEXT` 格式。`IO` 類型提供有關查詢讀取的資料表和結構描述的資訊。

## EXPLAIN ANALYZE 語法
<a name="athena-explain-analyze-statement"></a>

除了包含在 `EXPLAIN`，`EXPLAIN ANALYZE` 輸出也包含指定查詢的執行時間統計數字，例如 CPU 用量、資料列輸入數目以及資料列輸出數目。

```
EXPLAIN ANALYZE [ ( option [, ...]) ] statement
```

*option* 可為下列項目之一：

```
FORMAT { TEXT | JSON }
```

如果未指定 `FORMAT` 選項，則輸出預設為 `TEXT` 格式。因為 `EXPLAIN ANALYZE` 的所有查詢為 `DISTRIBUTED`，則 `TYPE` 選項不可為 `EXPLAIN ANALYZE`。

*陳述式*可為下列其中之一：

```
SELECT
CREATE TABLE AS SELECT
INSERT
UNLOAD
```

## EXPLAIN 範例
<a name="athena-explain-statement-examples"></a>

下列針對 `EXPLAIN` 的範例從較簡單的內容進展到較複雜的內容。

### 範例 1：使用 EXPLAIN 陳述式以文字格式顯示查詢計畫
<a name="athena-explain-statement-example-text-query-plan"></a>

在下列範例中，`EXPLAIN` 會顯示對 Elastic Load Balancing 日誌的 `SELECT` 查詢的執行計劃。格式預設為文字輸出。

```
EXPLAIN 
SELECT 
   request_timestamp, 
   elb_name, 
   request_ip 
FROM sampledb.elb_logs;
```

#### 結果
<a name="athena-explain-statement-example-text-query-plan-results"></a>

```
- Output[request_timestamp, elb_name, request_ip] => [[request_timestamp, elb_name, request_ip]]
    - RemoteExchange[GATHER] => [[request_timestamp, elb_name, request_ip]]
        - TableScan[awsdatacatalog:HiveTableHandle{schemaName=sampledb, tableName=elb_logs, 
analyzePartitionValues=Optional.empty}] => [[request_timestamp, elb_name, request_ip]]
                LAYOUT: sampledb.elb_logs
                request_ip := request_ip:string:2:REGULAR
                request_timestamp := request_timestamp:string:0:REGULAR
                elb_name := elb_name:string:1:REGULAR
```

### 範例 2：使用 EXPLAIN 繪製查詢計畫的圖形
<a name="athena-explain-statement-example-graph-a-query-plan"></a>

您可以使用 Athena 主控台來繪製查詢計劃圖。在查詢編輯器中輸入類似以下的 `SELECT` 陳述式，然後選擇 **EXPLAIN**。

```
SELECT 
      c.c_custkey,
      o.o_orderkey,
      o.o_orderstatus
   FROM tpch100.customer c 
   JOIN tpch100.orders o 
       ON c.c_custkey = o.o_custkey
```

Athena 查詢編輯器的 **Explain** (解釋) 頁面隨即開啟，並顯示查詢的分散式計劃和邏輯計劃。下圖顯示範例的邏輯計劃。

![\[Athena 查詢編輯器轉譯的查詢計劃圖。\]](http://docs.aws.amazon.com/zh_tw/athena/latest/ug/images/athena-explain-statement-tpch.png)


**重要**  
目前，即使 Athena 確實將這些篩選條件套用至您的查詢，有些分割區篩選條件可能不會顯示在巢狀運算子樹狀結構圖形中。若要驗證此等篩選條件的效果，請在查詢上執行 `EXPLAIN` 或 `EXPLAIN ANALYZE` 並查看結果。

如需在 Athena 主控台中使用查詢計劃圖形功能的詳細資訊，請參閱 [檢視 SQL 查詢的執行計畫](query-plans.md)。

### 範例 3：使用 EXPLAIN 陳述式來驗證分割區剔除
<a name="athena-explain-statement-example-verify-partition-pruning"></a>

當您對分割的金鑰使用篩選述詞來查詢分割的資料表時，查詢引擎會將述詞套用至分割的金鑰，以減少讀取的資料量。

以下範例使用 `EXPLAIN` 查詢，對分割資料表上的 `SELECT` 查詢驗證分割區剔除。首先，`CREATE TABLE` 陳述式會建立 `tpch100.orders_partitioned` 資料表。該資料表在資料欄 `o_orderdate` 上分割。

```
CREATE TABLE `tpch100.orders_partitioned`(
  `o_orderkey` int, 
  `o_custkey` int, 
  `o_orderstatus` string, 
  `o_totalprice` double, 
  `o_orderpriority` string, 
  `o_clerk` string, 
  `o_shippriority` int, 
  `o_comment` string)
PARTITIONED BY ( 
  `o_orderdate` string)
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
  's3://amzn-s3-demo-bucket/<your_directory_path>/'
```

`tpch100.orders_partitioned` 資料表在 `o_orderdate` 上有多個分割區，如 `SHOW PARTITIONS` 命令所示。

```
SHOW PARTITIONS tpch100.orders_partitioned;

o_orderdate=1994
o_orderdate=2015
o_orderdate=1998
o_orderdate=1995
o_orderdate=1993
o_orderdate=1997
o_orderdate=1992
o_orderdate=1996
```

下列 `EXPLAIN` 查詢會對指定 `SELECT` 陳述式驗證分割區剔除。

```
EXPLAIN 
SELECT 
   o_orderkey, 
   o_custkey, 
   o_orderdate 
FROM tpch100.orders_partitioned
WHERE o_orderdate = '1995'
```

#### 結果
<a name="athena-explain-statement-example-verify-partition-pruning-results"></a>

```
Query Plan
- Output[o_orderkey, o_custkey, o_orderdate] => [[o_orderkey, o_custkey, o_orderdate]]
    - RemoteExchange[GATHER] => [[o_orderkey, o_custkey, o_orderdate]]
        - TableScan[awsdatacatalog:HiveTableHandle{schemaName=tpch100, tableName=orders_partitioned, 
analyzePartitionValues=Optional.empty}] => [[o_orderkey, o_custkey, o_orderdate]]
                LAYOUT: tpch100.orders_partitioned
                o_orderdate := o_orderdate:string:-1:PARTITION_KEY
                    :: [[1995]]
                o_custkey := o_custkey:int:1:REGULAR
                o_orderkey := o_orderkey:int:0:REGULAR
```

結果中的粗體文字顯示述詞 `o_orderdate = '1995'` 已套用於 `PARTITION_KEY`。

### 範例 4：使用 EXPLAIN 查詢來檢查聯結順序和聯結類型
<a name="athena-explain-statement-example-check-join-order-and-type"></a>

下列 `EXPLAIN` 查詢會檢查 `SELECT` 陳述式的聯結順序和聯結類型。使用這樣的查詢來檢查查詢記憶體的使用情況，以便減少取得 `EXCEEDED_LOCAL_MEMORY_LIMIT` 錯誤的可能性。

```
EXPLAIN (TYPE DISTRIBUTED)
   SELECT 
      c.c_custkey, 
      o.o_orderkey,
      o.o_orderstatus
   FROM tpch100.customer c 
   JOIN tpch100.orders o 
       ON c.c_custkey = o.o_custkey 
   WHERE c.c_custkey = 123
```

#### 結果
<a name="athena-explain-statement-example-check-join-order-and-type-results"></a>

```
Query Plan
Fragment 0 [SINGLE]
    Output layout: [c_custkey, o_orderkey, o_orderstatus]
    Output partitioning: SINGLE []
    Stage Execution Strategy: UNGROUPED_EXECUTION
    - Output[c_custkey, o_orderkey, o_orderstatus] => [[c_custkey, o_orderkey, o_orderstatus]]
        - RemoteSource[1] => [[c_custkey, o_orderstatus, o_orderkey]]

Fragment 1 [SOURCE]
    Output layout: [c_custkey, o_orderstatus, o_orderkey]
    Output partitioning: SINGLE []
    Stage Execution Strategy: UNGROUPED_EXECUTION
    - CrossJoin => [[c_custkey, o_orderstatus, o_orderkey]]
            Distribution: REPLICATED
        - ScanFilter[table = awsdatacatalog:HiveTableHandle{schemaName=tpch100, 
tableName=customer, analyzePartitionValues=Optional.empty}, grouped = false, 
filterPredicate = ("c_custkey" = 123)] => [[c_custkey]]
                LAYOUT: tpch100.customer
                c_custkey := c_custkey:int:0:REGULAR
        - LocalExchange[SINGLE] () => [[o_orderstatus, o_orderkey]]
            - RemoteSource[2] => [[o_orderstatus, o_orderkey]]

Fragment 2 [SOURCE]
    Output layout: [o_orderstatus, o_orderkey]
    Output partitioning: BROADCAST []
    Stage Execution Strategy: UNGROUPED_EXECUTION
    - ScanFilterProject[table = awsdatacatalog:HiveTableHandle{schemaName=tpch100, 
tableName=orders, analyzePartitionValues=Optional.empty}, grouped = false, 
filterPredicate = ("o_custkey" = 123)] => [[o_orderstatus, o_orderkey]]
            LAYOUT: tpch100.orders
            o_orderstatus := o_orderstatus:string:2:REGULAR
            o_custkey := o_custkey:int:1:REGULAR
            o_orderkey := o_orderkey:int:0:REGULAR
```

查詢範例在交叉聯結中得到最佳化處理，以獲得更好的性能。結果顯示 `tpch100.orders` 將作為 `BROADCAST` 分佈類型進行分配。這意味著 `tpch100.orders` 資料表將分配到執行聯結操作的所有節點。`BROADCAST` 分佈類型會要求 `tpch100.orders` 資料表的所有篩選結果納入執行聯結操作的每個節點的記憶體。

不過，`tpch100.customer` 資料表比 `tpch100.orders` 小。由於 `tpch100.customer` 需要更少的記憶體，您可以將查詢重寫為 `BROADCAST tpch100.customer`，而非 `tpch100.orders`。這可減少查詢取得 `EXCEEDED_LOCAL_MEMORY_LIMIT` 錯誤的可能性。此策略假設下列要點：
+ 在 `tpch100.customer` 資料表中 `tpch100.customer.c_custkey` 為唯一。
+ 在 `tpch100.customer` 和 `tpch100.orders` 間有一對多的映射關係。

下列範例顯示重寫的查詢。

```
SELECT 
    c.c_custkey,
    o.o_orderkey,
    o.o_orderstatus
FROM tpch100.orders o
JOIN tpch100.customer c -- the filtered results of tpch100.customer are distributed to all nodes.
    ON c.c_custkey = o.o_custkey 
WHERE c.c_custkey = 123
```

### 範例 5：使用 EXPLAIN 查詢移除沒有效果的述詞
<a name="athena-explain-statement-example-remove-unneeded-predicates"></a>

您可以使用 `EXPLAIN` 查詢來檢查篩選述詞的有效性。您可以使用結果移除沒有效果的述詞，如下列範例所示。

```
EXPLAIN
   SELECT 
      c.c_name
   FROM tpch100.customer c
   WHERE c.c_custkey = CAST(RANDOM() * 1000 AS INT)
   AND c.c_custkey BETWEEN 1000 AND 2000
   AND c.c_custkey = 1500
```

#### 結果
<a name="athena-explain-statement-example-remove-unneeded-predicates-results"></a>

```
Query Plan
- Output[c_name] => [[c_name]]
    - RemoteExchange[GATHER] => [[c_name]]
        - ScanFilterProject[table = 
awsdatacatalog:HiveTableHandle{schemaName=tpch100, 
tableName=customer, analyzePartitionValues=Optional.empty}, 
filterPredicate = (("c_custkey" = 1500) AND ("c_custkey" = 
CAST(("random"() * 1E3) AS int)))] => [[c_name]]
                LAYOUT: tpch100.customer
                c_custkey := c_custkey:int:0:REGULAR
                c_name := c_name:string:1:REGULAR
```

結果中的 `filterPredicate` 顯示優化器將原始三個述詞合併為兩個述詞，並更改了應用程式的順序。

```
filterPredicate = (("c_custkey" = 1500) AND ("c_custkey" = CAST(("random"() * 1E3) AS int)))
```

因為結果顯示述詞 `AND c.c_custkey BETWEEN 1000 AND 2000` 沒有任何效果，您可以在不更改查詢結果的情況下移除此述詞。

如需有關 `EXPLAIN` 查詢結果中所使用術語的詳細資訊，請參閱[了解 Athena EXPLAIN 陳述式結果](athena-explain-statement-understanding.md)。

## EXPLAIN ANALYZE 範例
<a name="athena-explain-analyze-examples"></a>

下列範例將顯示範例 `EXPLAIN ANALYZE` 查詢和輸出。

### 範例 1：使用 EXPLAIN ANALYZE 以文字格式顯示查詢計畫和運算成本
<a name="athena-explain-analyze-example-cflogs-text"></a>

在下列範例中，`EXPLAIN ANALYZE` 會顯示對 CloudFront 日誌的 `SELECT` 查詢的執行計劃和運算成本。格式預設為文字輸出。

```
EXPLAIN ANALYZE SELECT FROM cloudfront_logs LIMIT 10
```

#### 結果
<a name="athena-explain-analyze-example-cflogs-text-results"></a>

```
 Fragment 1
     CPU: 24.60ms, Input: 10 rows (1.48kB); per task: std.dev.: 0.00, Output: 10 rows (1.48kB)
     Output layout: [date, time, location, bytes, requestip, method, host, uri, status, referrer,\
       os, browser, browserversion]
Limit[10] => [[date, time, location, bytes, requestip, method, host, uri, status, referrer, os,\
  browser, browserversion]]
             CPU: 1.00ms (0.03%), Output: 10 rows (1.48kB)
             Input avg.: 10.00 rows, Input std.dev.: 0.00%
LocalExchange[SINGLE] () => [[date, time, location, bytes, requestip, method, host, uri, status, referrer, os,\
 browser, browserversion]]
                 CPU: 0.00ns (0.00%), Output: 10 rows (1.48kB)
                 Input avg.: 0.63 rows, Input std.dev.: 387.30%
RemoteSource[2] => [[date, time, location, bytes, requestip, method, host, uri, status, referrer, os,\
  browser, browserversion]]
                     CPU: 1.00ms (0.03%), Output: 10 rows (1.48kB)
                     Input avg.: 0.63 rows, Input std.dev.: 387.30%

 Fragment 2
     CPU: 3.83s, Input: 998 rows (147.21kB); per task: std.dev.: 0.00, Output: 20 rows (2.95kB)
     Output layout: [date, time, location, bytes, requestip, method, host, uri, status, referrer, os,\
       browser, browserversion]
LimitPartial[10] => [[date, time, location, bytes, requestip, method, host, uri, status, referrer, os,\
  browser, browserversion]]
             CPU: 5.00ms (0.13%), Output: 20 rows (2.95kB)
             Input avg.: 166.33 rows, Input std.dev.: 141.42%
TableScan[awsdatacatalog:HiveTableHandle{schemaName=default, tableName=cloudfront_logs,\
  analyzePartitionValues=Optional.empty}, 
grouped = false] => [[date, time, location, bytes, requestip, method, host, uri, st
                 CPU: 3.82s (99.82%), Output: 998 rows (147.21kB)
                 Input avg.: 166.33 rows, Input std.dev.: 141.42%
                 LAYOUT: default.cloudfront_logs
                 date := date:date:0:REGULAR
                 referrer := referrer:string:9:REGULAR
                 os := os:string:10:REGULAR
                 method := method:string:5:REGULAR
                 bytes := bytes:int:3:REGULAR
                 browser := browser:string:11:REGULAR
                 host := host:string:6:REGULAR
                 requestip := requestip:string:4:REGULAR
                 location := location:string:2:REGULAR
                 time := time:string:1:REGULAR
                 uri := uri:string:7:REGULAR
                 browserversion := browserversion:string:12:REGULAR
                 status := status:int:8:REGULAR
```

### 範例 2：使用 EXPLAIN ANALYZE 以 JSON 格式顯示查詢計畫
<a name="athena-explain-analyze-example-cflogs-json"></a>

下列範例會顯示對 CloudFront 日誌的 `SELECT` 查詢的執行計劃和運算成本。此範例指定 JSON 作為輸出格式。

```
EXPLAIN ANALYZE (FORMAT JSON) SELECT * FROM cloudfront_logs LIMIT 10
```

#### 結果
<a name="athena-explain-analyze-example-cflogs-json-results"></a>

```
{ 
    "fragments": [{ 
        "id": "1", 
 
        "stageStats": { 
            "totalCpuTime": "3.31ms", 
            "inputRows": "10 rows", 
            "inputDataSize": "1514B", 
            "stdDevInputRows": "0.00", 
            "outputRows": "10 rows", 
            "outputDataSize": "1514B" 
        }, 
        "outputLayout": "date, time, location, bytes, requestip, method, host,\
           uri, status, referrer, os, browser, browserversion", 
 
        "logicalPlan": { 
            "1": [{ 
                "name": "Limit", 
                "identifier": "[10]", 
                "outputs": ["date", "time", "location", "bytes", "requestip", "method", "host",\
                  "uri", "status", "referrer", "os", "browser", "browserversion"], 
                "details": "", 
                "distributedNodeStats": { 
                    "nodeCpuTime": "0.00ns", 
                    "nodeOutputRows": 10, 
                    "nodeOutputDataSize": "1514B", 
                    "operatorInputRowsStats": [{ 
                        "nodeInputRows": 10.0, 
                        "nodeInputRowsStdDev": 0.0 
                    }] 
                }, 
                "children": [{ 
                    "name": "LocalExchange", 
                    "identifier": "[SINGLE] ()", 
                    "outputs": ["date", "time", "location", "bytes", "requestip", "method", "host",\
                      "uri", "status", "referrer", "os", "browser", "browserversion"], 
                    "details": "", 
                    "distributedNodeStats": { 
                        "nodeCpuTime": "0.00ns", 
                        "nodeOutputRows": 10, 
                        "nodeOutputDataSize": "1514B", 
                        "operatorInputRowsStats": [{ 
                            "nodeInputRows": 0.625, 
                            "nodeInputRowsStdDev": 387.2983346207417 
                        }] 
                    }, 
                    "children": [{ 
                        "name": "RemoteSource", 
                        "identifier": "[2]", 
                        "outputs": ["date", "time", "location", "bytes", "requestip", "method", "host",\
                          "uri", "status", "referrer", "os", "browser", "browserversion"], 
                        "details": "", 
                        "distributedNodeStats": { 
                            "nodeCpuTime": "0.00ns", 
                            "nodeOutputRows": 10, 
                            "nodeOutputDataSize": "1514B", 
                            "operatorInputRowsStats": [{ 
                                "nodeInputRows": 0.625, 
                                "nodeInputRowsStdDev": 387.2983346207417 
                            }] 
                        }, 
                        "children": [] 
                    }] 
                }] 
            }] 
        } 
    }, { 
        "id": "2", 
 
        "stageStats": { 
            "totalCpuTime": "1.62s", 
            "inputRows": "500 rows", 
            "inputDataSize": "75564B", 
            "stdDevInputRows": "0.00", 
            "outputRows": "10 rows", 
            "outputDataSize": "1514B" 
        }, 
        "outputLayout": "date, time, location, bytes, requestip, method, host, uri, status,\
           referrer, os, browser, browserversion", 
 
        "logicalPlan": { 
            "1": [{ 
                "name": "LimitPartial", 
                "identifier": "[10]", 
                "outputs": ["date", "time", "location", "bytes", "requestip", "method", "host", "uri",\
                  "status", "referrer", "os", "browser", "browserversion"], 
                "details": "", 
                "distributedNodeStats": { 
                    "nodeCpuTime": "0.00ns", 
                    "nodeOutputRows": 10, 
                    "nodeOutputDataSize": "1514B", 
                    "operatorInputRowsStats": [{ 
                        "nodeInputRows": 83.33333333333333, 
                        "nodeInputRowsStdDev": 223.60679774997897 
                    }] 
                }, 
                "children": [{ 
                    "name": "TableScan", 
                    "identifier": "[awsdatacatalog:HiveTableHandle{schemaName=default,\
                       tableName=cloudfront_logs, analyzePartitionValues=Optional.empty},\
                       grouped = false]", 
                    "outputs": ["date", "time", "location", "bytes", "requestip", "method", "host", "uri",\
                       "status", "referrer", "os", "browser", "browserversion"], 
                    "details": "LAYOUT: default.cloudfront_logs\ndate := date:date:0:REGULAR\nreferrer :=\
                       referrer: string:9:REGULAR\nos := os:string:10:REGULAR\nmethod := method:string:5:\
                       REGULAR\nbytes := bytes:int:3:REGULAR\nbrowser := browser:string:11:REGULAR\nhost :=\
                       host:string:6:REGULAR\nrequestip := requestip:string:4:REGULAR\nlocation :=\
                       location:string:2:REGULAR\ntime := time:string:1: REGULAR\nuri := uri:string:7:\
                       REGULAR\nbrowserversion := browserversion:string:12:REGULAR\nstatus :=\
                       status:int:8:REGULAR\n", 
                    "distributedNodeStats": { 
                        "nodeCpuTime": "1.62s", 
                        "nodeOutputRows": 500, 
                        "nodeOutputDataSize": "75564B", 
                        "operatorInputRowsStats": [{ 
                            "nodeInputRows": 83.33333333333333, 
                            "nodeInputRowsStdDev": 223.60679774997897 
                        }] 
                    }, 
                    "children": [] 
                }] 
            }] 
        } 
    }] 
}
```

## 其他資源
<a name="athena-explain-statement-additional-resources"></a>

如需其他資訊，請參閱以下資源。
+  [了解 Athena EXPLAIN 陳述式結果](athena-explain-statement-understanding.md)
+  [檢視 SQL 查詢的執行計畫](query-plans.md)
+  [檢視已完成查詢的統計資料和執行詳細資訊](query-stats.md)
+ Trino [https://trino.io/docs/current/sql/explain.html](https://trino.io/docs/current/sql/explain.html) 文件
+ Trino [https://trino.io/docs/current/sql/explain-analyze.html](https://trino.io/docs/current/sql/explain-analyze.html) 文件
+  *AWS 大數據部落格*中的[使用 Amazon Athena 中的 EXPLAIN 和 EXPLAIN ANALYZE 優化聯合查詢效能](https://aws.amazon.com/blogs/big-data/optimize-federated-query-performance-using-explain-and-explain-analyze-in-amazon-athena/)。

[![AWS Videos](http://img.youtube.com/vi/https://www.youtube.com/embed/7JUyTqglmNU/0.jpg)](http://www.youtube.com/watch?v=https://www.youtube.com/embed/7JUyTqglmNU)


# 了解 Athena EXPLAIN 陳述式結果
<a name="athena-explain-statement-understanding"></a>

本主題提供 Athena `EXPLAIN` 陳述式結果中使用的操作術語的簡要指南。

## EXPLAIN 陳述式輸出類型
<a name="athena-explain-statement-understanding-explain-plan-types"></a>

`EXPLAIN` 陳述式輸出可為以下兩種類型之一：
+ **邏輯計劃** – 顯示 SQL 引擎用來執行陳述式的邏輯計劃。此選項的語法為 `EXPLAIN` 或 `EXPLAIN (TYPE LOGICAL)`。
+ **分散式計劃** – 顯示分散式環境中的執行計劃。輸出顯示片段，這是處理階段。每個計劃片段會由一或多個節點處理。資料可以在處理片段的節點之間進行交換。此選項的語法為 `EXPLAIN (TYPE DISTRIBUTED)`。

  在分散式計畫的輸出中，用 `Fragment` *number* [*fragment\$1type*] 表示片段 (處理階段)，其中 *number* 是一個以零為起始的整數，以及 *fragment\$1type* 指定片段如何由節點執行。片段類型提供資料交換配置的深入資訊，如下表所述。  
**分散式計劃片段類型**    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/athena/latest/ug/athena-explain-statement-understanding.html)

## Exchange
<a name="athena-explain-statement-understanding-exchange-types"></a>

交換相關術語描述如何在工作節點之間交換資料。傳輸可以是本機或遠端。

**LocalExchange [*exchange\$1type*] **  
針對查詢的不同階段，在工作節點內本機傳輸資料。*exchange\$1type* 的值可以是邏輯或分散式交換類型其中一種，如本節後文所述。

**RemoteExchange [*exchange\$1type*] **  
針對查詢的不同階段，在工作節點之間傳輸資料。*exchange\$1type* 的值可以是邏輯或分散式交換類型其中一種，如本節後文所述。

### 邏輯 Exchange 類型
<a name="athena-explain-statement-understanding-exchange-types-logical"></a>

下列交換類型說明邏輯計劃的交換階段期間所採取的動作。
+ **`GATHER`** – 單一工作節點會收集所有其他工作節點的輸出。例如，選取查詢的最後階段會收集所有節點的結果，並將結果寫入 Amazon S3。
+ **`REPARTITION`** – 根據套用至下一個運算子所需的分割結構描述，將資料行資料傳送至特定工作者。
+ **`REPLICATE`** – 將資料行資料複製到所有工作者。

### 分散式交換類型
<a name="athena-explain-statement-understanding-exchange-types-distributed"></a>

下列交換類型指出在分散式計劃中的節點之間交換資料時的資料配置。
+ **`HASH`** – 交換會使用雜湊函數將資料分配到多個目的地。
+ **`SINGLE`** – 交換會將資料分配到單一目的地。

## 掃描
<a name="athena-explain-statement-understanding-scanning"></a>

下列術語描述查詢期間如何掃描資料。

**TableScan **  
掃描來自 Amazon S3 或 Apache Hive 連接器的資料表來源資料，並套用從篩選述詞產生的分割區剔除。

**ScanFilter **  
掃描來自 Amazon S3 或 Hive 連接器的資料表來源資料，並套用從篩選述詞產生的分割區剔除，以及從沒有透過分割區剔除套用的其他篩選述詞產生的分割區剔除。

**ScanFilterProject **  
首先，掃描來自 Amazon S3 或 Hive 連接器的資料表來源資料，並套用從篩選述詞產生的分割區剔除，以及從沒有透過分割區剔除套用的其他篩選述詞產生的分割區剔除。然後，將輸出資料的記憶體配置修改為新的投影，以改善後續階段的效能。

## Join
<a name="athena-explain-statement-understanding-join"></a>

聯結兩個資料表之間的資料。聯結可以依聯結類型和分佈類型來分類。

### 聯結類型
<a name="athena-explain-statement-understanding-join-types"></a>

聯結類型定義聯結操作發生的方式。

**CrossJoin** – 產生已聯結的兩個資料表的笛卡兒乘積。

**InnerJoin** – 選取兩個資料表中具有相符值的記錄。

**LeftJoin** – 選取左資料表中的所有記錄，以及右資料表中的相符記錄。如果沒有發生匹配，右側的結果是 NULL。

**RightJoin** – 選取右資料表中的所有記錄，以及左資料表中的相符記錄。如果沒有發生匹配，左側的結果是 NULL。

**FullJoin** – 選取左側或右側資料表記錄中有相符項目的所有記錄。聯結資料表包含來自兩個資料表的所有記錄，並在兩側不符的地方以 NULL 填充。

**注意**  
基於效能考量，查詢引擎可以將聯結查詢重新寫入不同的聯結類型，以產生相同的結果。例如，在一個資料表上具有述詞的內部聯結查詢可以重寫入 `CrossJoin`。這會將述詞推送到資料表的掃描階段，以便掃描較少的資料。

### 聯結分佈類型
<a name="athena-explain-statement-understanding-join-distribution-types"></a>

分佈類型定義執行聯結操作時，如何在工作節點之間交換資料。

**已分割** – 左側和右側資料表會在所有工作節點間進行雜湊分割。已分割分佈會在每個節點消耗較少的記憶體。已分割分佈可以比複寫的聯結慢得多。當您聯結兩個大資料表時適合使用已分割聯結。

**已複寫** – 一個資料表會在所有工作節點之間進行雜湊分割，另一個資料表會複寫到所有工作節點，以執行聯結操作。複寫的分佈可以比已分割聯結快得多，但它會在每個工作節點中耗用更多的記憶體。如果複寫的資料表太大，工作節點可能會遇到記憶體不足錯誤。當其中一個聯結的資料表很小時，就適合使用複寫的聯結。

# PREPARE
<a name="sql-prepare"></a>

使用名稱 `statement_name` 建立 SQL 陳述式，以供之後執行。陳述式可以包含以問號表示的參數。若要提供值給參數並執行預備陳述式，請使用 [EXECUTE](sql-execute.md)。

## 概要
<a name="sql-prepare-synopsis"></a>

```
PREPARE statement_name FROM statement
```

下表描述了參數。


****  

| 參數 | Description | 
| --- | --- | 
| statement\$1name | 要預備之陳述式的名稱。該名稱在工作群組內必須是唯一的。 | 
| statement | SELECT、CTAS 或 INSERT INTO 查詢。 | 

**注意**  
工作群組中預備陳述式的數量上限為 1000。

## 範例
<a name="sql-prepare-examples"></a>

以下範例準備一個不含參數的選擇查詢。

```
PREPARE my_select1 FROM 
SELECT * FROM nation
```

以下範例準備一個包含參數的選擇查詢。`productid` 和 `quantity` 的值將由 `EXECUTE` 陳述式的 `USING` 子句提供：

```
PREPARE my_select2 FROM 
SELECT order FROM orders WHERE productid = ? and quantity < ?
```

以下範例準備一個插入查詢。

```
PREPARE my_insert FROM 
INSERT INTO cities_usa (city, state) 
SELECT city, state 
FROM cities_world 
WHERE country = ?
```

## 其他資源
<a name="sql-prepare-additional-resources"></a>

[使用預備陳述式](querying-with-prepared-statements-querying.md)

[EXECUTE](sql-execute.md)

[DEALLOCATE PREPARE](sql-deallocate-prepare.md)

[INSERT INTO](insert-into.md)

# EXECUTE
<a name="sql-execute"></a>

執行名為 `statement_name` 的預備陳述式。預備陳述式中問號的參數值定義在以逗號分隔的清單的 `USING` 子句中。若要建立預備陳述式，使用 [PREPARE](sql-prepare.md)。

## 概要
<a name="sql-execute-synopsis"></a>

```
EXECUTE statement_name [ USING parameter1[, parameter2, ... ] ]
```

## 範例
<a name="sql-execute-examples"></a>

以下範例準備並執行不含任何參數的查詢。

```
PREPARE my_select1 FROM 
SELECT name FROM nation 
EXECUTE my_select1
```

以下範例準備並執行含有一個參數的查詢。

```
PREPARE my_select2 FROM 
SELECT * FROM "my_database"."my_table" WHERE year = ? 
EXECUTE my_select2 USING 2012
```

這相當於：

```
SELECT * FROM "my_database"."my_table" WHERE year = 2012
```

以下範例準備並執行含有兩個參數的查詢。

```
PREPARE my_select3 FROM 
SELECT order FROM orders WHERE productid = ? and quantity < ? 
EXECUTE my_select3 USING 346078, 12
```

## 其他資源
<a name="sql-execute-additional-resources"></a>

[使用預備陳述式](querying-with-prepared-statements-querying.md)

[PREPARE](sql-prepare.md)

[INSERT INTO](insert-into.md)

# DEALLOCATE PREPARE
<a name="sql-deallocate-prepare"></a>

從目前工作群組的預備陳述式中移除具有指定名稱的預備陳述式。

## 概要
<a name="sql-deallocate-prepare-synopsis"></a>

```
DEALLOCATE PREPARE statement_name
```

## 範例
<a name="sql-deallocate-prepare-examples"></a>

下列範例會從目前的工作群組中移除 `my_select1` 預備陳述式。

```
DEALLOCATE PREPARE my_select1
```

## 其他資源
<a name="sql-deallocate-prepare-additional-resources"></a>

[使用預備陳述式](querying-with-prepared-statements-querying.md)

[PREPARE](sql-prepare.md)

# UNLOAD
<a name="unload"></a>

從 `SELECT` 陳述式寫入查詢結果至指定的資料格式。針對 `UNLOAD` 支援的格式包括 Apache Parquet、ORC、Apache Avro 和 JSON。CSV 是 Athena `SELECT` 命令支援的唯一輸出格式，但您可以使用支援各種輸出格式的 `UNLOAD` 命令來括住 `SELECT` 查詢，並將其輸出重寫為 `UNLOAD` 支援的其中一種格式。

雖然您可以使用 `CREATE TABLE AS` (CTAS) 陳述式以 CSV 以外的格式輸出資料，但 CTAS 陳述式需要在 Athena 中建立資料表。`UNLOAD` 陳述式在您想以非 CSV 格式輸出 `SELECT` 查詢結果，但不要相關聯的資料表時十分有用。例如，下游應用程式可能需要 `SELECT` 查詢結果使用 JSON 格式，而且如果您打算對其他分析使用 `SELECT` 查詢結果，則 Parquet 或 ORC 的效能可能優於 CSV。

## 考量和限制
<a name="unload-considerations-and-limitations"></a>

當您在 Athena 中使用 `UNLOAD` 陳述式時，請謹記以下幾點：
+ **沒有檔案的全域排序** – `UNLOAD`結果會同時寫入多個檔案。如果 `UNLOAD` 陳述式中的 `SELECT` 查詢會指定排序順序，則每個檔案的內容會依排序順序排列，但檔案並不會彼此排序。
+ **未刪除孤立資料** – 在發生故障的情況下，Athena 不會嘗試刪除孤立的資料。此行為同於 CTAS 和 `INSERT INTO` 陳述式。
+ **分割區數量上限** – 可搭配 `UNLOAD` 使用的分割區數量上限為 100。
+ **中繼資料和資訊清單檔案** – Athena 會為每個 `UNLOAD` 查詢產生中繼資料檔案和資訊清單檔案。資訊清單會追蹤查詢寫入的檔案。這兩個檔案都會儲存到 Amazon S3 中的 Athena 查詢結果位置。如需詳細資訊，請參閱[識別查詢輸出檔案](querying-finding-output-files.md#querying-identifying-output-files)。
+ **加密** – `UNLOAD` 輸出檔案會根據用於 Amazon S3 的加密組態進行加密。若要設定加密組態來加密 `UNLOAD` 結果，您可以使用 [EncryptionConfiguration API](https://docs.aws.amazon.com/athena/latest/APIReference/API_EncryptionConfiguration.html)。
+ **預備陳述式** – `UNLOAD` 可以與預備的陳述式一起使用。如需有關 Athena 中的預備陳述式的資訊，請參閱[使用參數化查詢](querying-with-prepared-statements.md)。
+ **服務配額** – `UNLOAD` 會使用 DML 查詢配額。如需有關配額的資訊，請參閱 [Service Quotas](service-limits.md)。
+ **預期的儲存貯體擁有者** – 預期的儲存貯體擁有者設定不適用於 `UNLOAD` 查詢中指定的目的地 Amazon S3 位置。預期的儲存貯體擁有者設定僅適用於您為 Athena 查詢結果指定的 Amazon S3 輸出位置。如需詳細資訊，請參閱[使用 Athena 主控台指定查詢結果位置](query-results-specify-location-console.md)。

## 語法
<a name="unload-syntax"></a>

`UNLOAD` 陳述式使用下列語法。

```
UNLOAD (SELECT col_name[, ...] FROM old_table) 
TO 's3://amzn-s3-demo-bucket/my_folder/' 
WITH ( property_name = 'expression' [, ...] )
```

除了寫入分割區時，`TO` 目標必須在沒有資料的 Amazon S3 中指定位置。在 `UNLOAD` 查詢寫入指定位置之前，它會驗證儲存貯體位置是否為空。由於 `UNLOAD` 在指定位置已經有資料時不會將資料寫入該位置，`UNLOAD` 不會覆寫現有資料。若要重複使用儲存貯體位置作為 `UNLOAD` 的目標，請刪除儲存貯體位置中的資料，然後再次執行查詢。

請注意，當 `UNLOAD` 寫入分割區時，此行為會有所不同。如果您多次執行具有相同 `SELECT` 陳述式、相同 `TO` 位置和相同分割區的相同 `UNLOAD` 查詢，則每個 `UNLOAD` 查詢都會在指定的位置和分割區將資料卸載至 Amazon S3。

### Parameters
<a name="unload-parameters"></a>

*property\$1name* 可能的值如下。

** 格式 = '*file\$1format*'**  
必要。指定輸出的檔案格式。*file\$1format* 的可能值為 `ORC`、`PARQUET`、`AVRO`、`JSON` 或 `TEXTFILE`。

** 壓縮 = '*compression\$1format*'**  
選用。此選項僅適用於 ORC 和 Parquet 格式。ORC 的預設值為 `zlib`，而 Parquet 的預設值則為 `gzip`。如需有關支援的壓縮格式的資訊，請參閱 [Athena 壓縮支援](https://docs.aws.amazon.com/athena/latest/ug/compression-formats.html)。  
此選項不適用於 `AVRO` 格式。Athena 對 `JSON` 和 `TEXTFILE` 格式使用 `gzip`。

**compression\$1level = *compression\$1level* **  
選用。用於 ZSTD 壓縮的壓縮級別。此屬性僅適用於 ZSTD 壓縮。如需詳細資訊，請參閱[使用 ZSTD 壓縮級別](compression-support-zstd-levels.md)。

** field\$1delimiter = '*delimiter*'**  
選用。指定 CSV、TSV 和其他文字格式檔案的單一字元欄位分隔符號。以下範例指定逗點分隔符號。  

```
WITH (field_delimiter = ',')
```
目前不支援多字元欄位分隔符號。如果您未指定欄位分隔符號，系統會使用八進位制字元 `\001` (^A)。

** partitioned\$1by = ARRAY[ *col\$1name*[,...] ] **  
選用。資料欄的陣列清單，輸出依這些資料欄進行分割。  
在 `SELECT` 陳列式中，請確保已分割資料欄的名稱位於資料欄清單中的最後。

## 範例
<a name="unload-examples"></a>

下列範例會使用 JSON 格式，將 `SELECT` 查詢的輸出寫入 Amazon S3 位置 `s3://amzn-s3-demo-bucket/unload_test_1/`。

```
UNLOAD (SELECT * FROM old_table) 
TO 's3://amzn-s3-demo-bucket/unload_test_1/' 
WITH (format = 'JSON')
```

下列範例會採用 Snappy 壓縮方式以 Parquet 格式寫入 `SELECT` 查詢的輸出。

```
UNLOAD (SELECT * FROM old_table) 
TO 's3://amzn-s3-demo-bucket/' 
WITH (format = 'PARQUET',compression = 'SNAPPY')
```

下列範例會以文字格式寫入四個資料欄，且輸出依最後一個資料欄分割。

```
UNLOAD (SELECT name1, address1, comment1, key1 FROM table1) 
TO 's3://amzn-s3-demo-bucket/ partitioned/' 
WITH (format = 'TEXTFILE', partitioned_by = ARRAY['key1'])
```

下列範例會使用 Parquet 檔案格式、ZSTD 壓縮和 ZSTD 壓縮級別 4，將查詢結果卸載到指定的位置。

```
UNLOAD (SELECT * FROM old_table) 
TO 's3://amzn-s3-demo-bucket/' 
WITH (format = 'PARQUET', compression = 'ZSTD', compression_level = 4)
```

## 其他資源
<a name="unload-additional-resources"></a>
+ *AWS 大數據部落格*中的[使用 Amazon Athena UNLOAD 特徵簡化 ETL 和 ML 管道](https://aws.amazon.com/blogs/big-data/simplify-your-etl-and-ml-pipelines-using-the-amazon-athena-unload-feature/)。

# Amazon Athena 中的函數
<a name="functions"></a>

如需有關 Athena 引擎版本之間函式的變更，請參閱 [Athena 引擎版本控制](engine-versions.md)。如需可與 `AT TIME ZONE` 運算子搭配使用的時區清單，請參閱[使用支援的時區](athena-supported-time-zones.md)。

**Topics**
+ [Athena 引擎版本 3](functions-env3.md)

# Athena 引擎版本 3 函式
<a name="functions-env3"></a>

Athena 引擎版本 3 中的函數以 Trino 為基礎。如需有關 Trino 函數、運算子和表達式的資訊，請參閱 Trino 文件中的 [Functions and operators](https://trino.io/docs/current/functions.html) (函數和運算子)，以及以下具體子節。
+  [Aggregate](https://trino.io/docs/current/functions/aggregate.html) 
+  [Array](https://trino.io/docs/current/functions/array.html) (陣列) 
+  [：二進位](https://trino.io/docs/current/functions/binary.html) 
+  [Bitwise](https://trino.io/docs/current/functions/bitwise.html) (位元) 
+  [Color (顏色)](https://trino.io/docs/current/functions/color.html) 
+  [Comparison](https://trino.io/docs/current/functions/comparison.html) (比較) 
+  [有條件](https://trino.io/docs/current/functions/conditional.html) 
+  [Conversion](https://trino.io/docs/current/functions/conversion.html) (轉換) 
+  [日期和時間](https://trino.io/docs/current/functions/datetime.html) 
+  [Decimal](https://trino.io/docs/current/functions/decimal.html) (小數) 
+  [Geospatial](https://trino.io/docs/current/functions/geospatial.html) (地理空間) 
+  [HyperLogLog](https://trino.io/docs/current/functions/hyperloglog.html) 
+  [IP Address](https://trino.io/docs/current/functions/ipaddress.html) (IP 地址) 
+  [JSON](https://trino.io/docs/current/functions/json.html) 
+  [Lambda](https://trino.io/docs/current/functions/lambda.html) 
+  [Logical](https://trino.io/docs/current/functions/logical.html) (邏輯) 
+  [Machine learning](https://trino.io/docs/current/functions/ml.html) (機器學習) 
+  [Map](https://trino.io/docs/current/functions/map.html) 
+  [Math](https://trino.io/docs/current/functions/math.html) 
+  [Quantile digest](https://trino.io/docs/current/functions/qdigest.html) (分位數摘要) 
+  [Regular expression](https://trino.io/docs/current/functions/regexp.html) (常規表達式) 
+  [Session](https://trino.io/docs/current/functions/session.html) (工作階段) 
+  [Set Digest](https://trino.io/docs/current/functions/setdigest.html) 
+  [：字串](https://trino.io/docs/current/functions/string.html) 
+  [資料表](https://trino.io/docs/current/functions/table.html) 
+  [Teradata](https://trino.io/docs/current/functions/teradata.html) 
+  [T-Digest](https://trino.io/docs/current/functions/tdigest.html) 
+  [URL](https://trino.io/docs/current/functions/url.html) 
+  [UUID](https://trino.io/docs/current/functions/uuid.html) 
+  [視窗](https://trino.io/docs/current/functions/window.html) 

## invoker\$1principal() 函式
<a name="functions-env3-invoker-principal"></a>

`invoker_principal` 函式是 Athena 引擎版本 3 所獨有的，Trino 中找不到該函式。

傳回包含主體 (IAM 角色或 Identity Center 身分) 的 ARN 的 `VARCHAR`，其中該主體可執行呼叫函式的查詢。例如，如果查詢調用者使用 IAM 角色的許可來執行查詢，則函式會傳回 IAM 角色的 ARN。執行查詢的角色必須允許 `LakeFormation:GetDataLakePrincipal` 動作。

### Usage
<a name="functions-invoker-principal-usage"></a>

```
SELECT invoker_principal()
```

下列資料表會顯示範例結果。


****  

| \$1 | \$1col0 | 
| --- | --- | 
| 1 | arn:aws:iam::111122223333:role/Admin | 

# 使用支援的時區
<a name="athena-supported-time-zones"></a>

您可以在 `SELECT timestamp` 陳述式中使用 `AT TIME ZONE` 運算子來指定傳回之時間戳記的時區，如以下範例所示：

```
SELECT timestamp '2012-10-31 01:00 UTC' AT TIME ZONE 'America/Los_Angeles' AS la_time;
```

**結果**

```
la_time

2012-10-30 18:00:00.000 America/Los_Angeles
```

如需 Athena 中支援的時區清單，請展開本主題結尾的 [支援的時區清單](#athena-supported-time-zones-list)。

## 時區函數和範例
<a name="athena-supported-time-zones-functions-examples"></a>

以下是一些其他與時區相關的函數和範例。
+ **at\$1timezone(*timestamp*, *zone*)** – 傳回*區域*相應當地時間的*時間戳記*值。

  **範例**

  ```
  SELECT at_timezone(timestamp '2021-08-22 00:00 UTC', 'Canada/Newfoundland')
  ```

  **結果**

  ```
  2021-08-21 21:30:00.000 Canada/Newfoundland
  ```
+ **timezone\$1hour(*timestamp*)** – 以 `bigint` 傳回時區偏離時間戳記的小時數。

  **範例**

  ```
  SELECT timezone_hour(timestamp '2021-08-22 04:00 UTC' AT TIME ZONE 'Canada/Newfoundland')
  ```

  **結果**

  ```
  -2
  ```
+ **timezone\$1minute(*timestamp*)** – 以 `bigint` 傳回時區偏離*時間戳記*的分鐘數 。

  **範例**

  ```
  SELECT timezone_minute(timestamp '2021-08-22 04:00 UTC' AT TIME ZONE 'Canada/Newfoundland')
  ```

  **結果**

  ```
  -30
  ```
+ **with\$1timezone(*timestamp*, *zone*)** – 從指定的*時間戳記*和*區域*值傳回時間戳記和時區。

  **範例**

  ```
  SELECT with_timezone(timestamp '2021-08-22 04:00', 'Canada/Newfoundland')
  ```

  **結果**

  ```
  2021-08-22 04:00:00.000 Canada/Newfoundland
  ```

## 支援的時區清單
<a name="athena-supported-time-zones-list"></a>

下列清單包含可搭配 Athena 中 `AT TIME ZONE` 運算子使用的時區。如需其他與時區相關的函數和範例，請參閱 [時區函數和範例](#athena-supported-time-zones-functions-examples)。

```
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
Africa/El_Aaiun
Africa/Freetown
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Juba
Africa/Kampala
Africa/Khartoum
Africa/Kigali
Africa/Kinshasa
Africa/Lagos
Africa/Libreville
Africa/Lome
Africa/Luanda
Africa/Lubumbashi
Africa/Lusaka
Africa/Malabo
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Mogadishu
Africa/Monrovia
Africa/Nairobi
Africa/Ndjamena
Africa/Niamey
Africa/Nouakchott
Africa/Ouagadougou
Africa/Porto-Novo
Africa/Sao_Tome
Africa/Timbuktu
Africa/Tripoli
Africa/Tunis
Africa/Windhoek
America/Adak
America/Anchorage
America/Anguilla
America/Antigua
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/Cordoba
America/Argentina/Jujuy
America/Argentina/La_Rioja
America/Argentina/Mendoza
America/Argentina/Rio_Gallegos
America/Argentina/Salta
America/Argentina/San_Juan
America/Argentina/San_Luis
America/Argentina/Tucuman
America/Argentina/Ushuaia
America/Aruba
America/Asuncion
America/Atikokan
America/Atka
America/Bahia
America/Bahia_Banderas
America/Barbados
America/Belem
America/Belize
America/Blanc-Sablon
America/Boa_Vista
America/Bogota
America/Boise
America/Buenos_Aires
America/Cambridge_Bay
America/Campo_Grande
America/Cancun
America/Caracas
America/Catamarca
America/Cayenne
America/Cayman
America/Chicago
America/Chihuahua
America/Coral_Harbour
America/Cordoba
America/Costa_Rica
America/Creston
America/Cuiaba
America/Curacao
America/Danmarkshavn
America/Dawson
America/Dawson_Creek
America/Denver
America/Detroit
America/Dominica
America/Edmonton
America/Eirunepe
America/El_Salvador
America/Ensenada
America/Fort_Nelson
America/Fort_Wayne
America/Fortaleza
America/Glace_Bay
America/Godthab
America/Goose_Bay
America/Grand_Turk
America/Grenada
America/Guadeloupe
America/Guatemala
America/Guayaquil
America/Guyana
America/Halifax
America/Havana
America/Hermosillo
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Indianapolis
America/Inuvik
America/Iqaluit
America/Jamaica
America/Jujuy
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Knox_IN
America/Kralendijk
America/La_Paz
America/Lima
America/Los_Angeles
America/Louisville
America/Lower_Princes
America/Maceio
America/Managua
America/Manaus
America/Marigot
America/Martinique
America/Matamoros
America/Mazatlan
America/Mendoza
America/Menominee
America/Merida
America/Metlakatla
America/Mexico_City
America/Miquelon
America/Moncton
America/Monterrey
America/Montevideo
America/Montreal
America/Montserrat
America/Nassau
America/New_York
America/Nipigon
America/Nome
America/Noronha
America/North_Dakota/Beulah
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/Ojinaga
America/Panama
America/Pangnirtung
America/Paramaribo
America/Phoenix
America/Port-au-Prince
America/Port_of_Spain
America/Porto_Acre
America/Porto_Velho
America/Puerto_Rico
America/Punta_Arenas
America/Rainy_River
America/Rankin_Inlet
America/Recife
America/Regina
America/Resolute
America/Rio_Branco
America/Rosario
America/Santa_Isabel
America/Santarem
America/Santiago
America/Santo_Domingo
America/Sao_Paulo
America/Scoresbysund
America/Shiprock
America/Sitka
America/St_Barthelemy
America/St_Johns
America/St_Kitts
America/St_Lucia
America/St_Thomas
America/St_Vincent
America/Swift_Current
America/Tegucigalpa
America/Thule
America/Thunder_Bay
America/Tijuana
America/Toronto
America/Tortola
America/Vancouver
America/Virgin
America/Whitehorse
America/Winnipeg
America/Yakutat
America/Yellowknife
Antarctica/Casey
Antarctica/Davis
Antarctica/DumontDUrville
Antarctica/Macquarie
Antarctica/Mawson
Antarctica/McMurdo
Antarctica/Palmer
Antarctica/Rothera
Antarctica/South_Pole
Antarctica/Syowa
Antarctica/Troll
Antarctica/Vostok
Arctic/Longyearbyen
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Ashkhabad
Asia/Atyrau
Asia/Baghdad
Asia/Bahrain
Asia/Baku
Asia/Bangkok
Asia/Barnaul
Asia/Beirut
Asia/Bishkek
Asia/Brunei
Asia/Calcutta
Asia/Chita
Asia/Choibalsan
Asia/Chongqing
Asia/Chungking
Asia/Colombo
Asia/Dacca
Asia/Damascus
Asia/Dhaka
Asia/Dili
Asia/Dubai
Asia/Dushanbe
Asia/Gaza
Asia/Harbin
Asia/Hebron
Asia/Ho_Chi_Minh
Asia/Hong_Kong
Asia/Hovd
Asia/Irkutsk
Asia/Istanbul
Asia/Jakarta
Asia/Jayapura
Asia/Jerusalem
Asia/Kabul
Asia/Kamchatka
Asia/Karachi
Asia/Kashgar
Asia/Kathmandu
Asia/Katmandu
Asia/Khandyga
Asia/Kolkata
Asia/Krasnoyarsk
Asia/Kuala_Lumpur
Asia/Kuching
Asia/Kuwait
Asia/Macao
Asia/Macau
Asia/Magadan
Asia/Makassar
Asia/Manila
Asia/Muscat
Asia/Nicosia
Asia/Novokuznetsk
Asia/Novosibirsk
Asia/Omsk
Asia/Oral
Asia/Phnom_Penh
Asia/Pontianak
Asia/Pyongyang
Asia/Qatar
Asia/Qyzylorda
Asia/Rangoon
Asia/Riyadh
Asia/Saigon
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
Asia/Taipei
Asia/Tashkent
Asia/Tbilisi
Asia/Tehran
Asia/Tel_Aviv
Asia/Thimbu
Asia/Thimphu
Asia/Tokyo
Asia/Tomsk
Asia/Ujung_Pandang
Asia/Ulaanbaatar
Asia/Ulan_Bator
Asia/Urumqi
Asia/Ust-Nera
Asia/Vientiane
Asia/Vladivostok
Asia/Yakutsk
Asia/Yangon
Asia/Yekaterinburg
Asia/Yerevan
Atlantic/Azores
Atlantic/Bermuda
Atlantic/Canary
Atlantic/Cape_Verde
Atlantic/Faeroe
Atlantic/Faroe
Atlantic/Jan_Mayen
Atlantic/Madeira
Atlantic/Reykjavik
Atlantic/South_Georgia
Atlantic/St_Helena
Atlantic/Stanley
Australia/ACT
Australia/Adelaide
Australia/Brisbane
Australia/Broken_Hill
Australia/Canberra
Australia/Currie
Australia/Darwin
Australia/Eucla
Australia/Hobart
Australia/LHI
Australia/Lindeman
Australia/Lord_Howe
Australia/Melbourne
Australia/NSW
Australia/North
Australia/Perth
Australia/Queensland
Australia/South
Australia/Sydney
Australia/Tasmania
Australia/Victoria
Australia/West
Australia/Yancowinna
Brazil/Acre
Brazil/DeNoronha
Brazil/East
Brazil/West
CET
CST6CDT
Canada/Atlantic
Canada/Central
Canada/Eastern
Canada/Mountain
Canada/Newfoundland
Canada/Pacific
Canada/Saskatchewan
Canada/Yukon
Chile/Continental
Chile/EasterIsland
Cuba
EET
EST5EDT
Egypt
Eire
Europe/Amsterdam
Europe/Andorra
Europe/Astrakhan
Europe/Athens
Europe/Belfast
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Bucharest
Europe/Budapest
Europe/Busingen
Europe/Chisinau
Europe/Copenhagen
Europe/Dublin
Europe/Gibraltar
Europe/Guernsey
Europe/Helsinki
Europe/Isle_of_Man
Europe/Istanbul
Europe/Jersey
Europe/Kaliningrad
Europe/Kiev
Europe/Kirov
Europe/Lisbon
Europe/Ljubljana
Europe/London
Europe/Luxembourg
Europe/Madrid
Europe/Malta
Europe/Mariehamn
Europe/Minsk
Europe/Monaco
Europe/Moscow
Europe/Nicosia
Europe/Oslo
Europe/Paris
Europe/Podgorica
Europe/Prague
Europe/Riga
Europe/Rome
Europe/Samara
Europe/San_Marino
Europe/Sarajevo
Europe/Simferopol
Europe/Skopje
Europe/Sofia
Europe/Stockholm
Europe/Tallinn
Europe/Tirane
Europe/Tiraspol
Europe/Ulyanovsk
Europe/Uzhgorod
Europe/Vaduz
Europe/Vatican
Europe/Vienna
Europe/Vilnius
Europe/Volgograd
Europe/Warsaw
Europe/Zagreb
Europe/Zaporozhye
Europe/Zurich
GB
GB-Eire
Hongkong
Iceland
Indian/Antananarivo
Indian/Chagos
Indian/Christmas
Indian/Cocos
Indian/Comoro
Indian/Kerguelen
Indian/Mahe
Indian/Maldives
Indian/Mauritius
Indian/Mayotte
Indian/Reunion
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST7MDT
Mexico/BajaNorte
Mexico/BajaSur
Mexico/General
NZ
NZ-CHAT
Navajo
PRC
PST8PDT
Pacific/Apia
Pacific/Auckland
Pacific/Bougainville
Pacific/Chatham
Pacific/Chuuk
Pacific/Easter
Pacific/Efate
Pacific/Enderbury
Pacific/Fakaofo
Pacific/Fiji
Pacific/Funafuti
Pacific/Galapagos
Pacific/Gambier
Pacific/Guadalcanal
Pacific/Guam
Pacific/Honolulu
Pacific/Johnston
Pacific/Kiritimati
Pacific/Kosrae
Pacific/Kwajalein
Pacific/Majuro
Pacific/Marquesas
Pacific/Midway
Pacific/Nauru
Pacific/Niue
Pacific/Norfolk
Pacific/Noumea
Pacific/Pago_Pago
Pacific/Palau
Pacific/Pitcairn
Pacific/Pohnpei
Pacific/Ponape
Pacific/Port_Moresby
Pacific/Rarotonga
Pacific/Saipan
Pacific/Samoa
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
Pacific/Truk
Pacific/Wake
Pacific/Wallis
Pacific/Yap
Poland
Portugal
ROK
Singapore
Turkey
US/Alaska
US/Aleutian
US/Arizona
US/Central
US/East-Indiana
US/Eastern
US/Hawaii
US/Indiana-Starke
US/Michigan
US/Mountain
US/Pacific
US/Pacific-New
US/Samoa
W-SU
WET
```