

# AWS CLI を使用して、プリペアドステートメントを作成する
<a name="querying-with-prepared-statements-creating-prepared-statements-using-the-aws-cli"></a>

AWS CLI を使用してプリペアドステートメントを作成するには、次のいずれかの `athena` コマンドを使用できます。
+ `create-prepared-statement` コマンドを使用して、実行パラメータを持つクエリステートメントを指定します。
+ `start-query-execution` コマンドを使用して、`PREPARE` 構文を使用するクエリ文字列を指定します。

## create-prepared-statement を使用する
<a name="querying-with-prepared-statements-cli-using-create-prepared-statement"></a>

次の例のように、`create-prepared-statement` コマンドにおいて、`query-statement` 引数でクエリテキストを定義します。

```
aws athena create-prepared-statement 
--statement-name PreparedStatement1 
--query-statement "SELECT * FROM table WHERE x = ?" 
--work-group athena-engine-v2
```

## start-query-execution および PREPARE 構文を使用する
<a name="querying-with-prepared-statements-cli-using-start-query-execution-and-the-prepare-syntax"></a>

`start-query-execution` コマンドを使用します。次の例のように、`PREPARE` ステートメントを `query-string` 引数に含めます。

```
aws athena start-query-execution 
--query-string "PREPARE PreparedStatement1 FROM SELECT * FROM table WHERE x = ?" 
--query-execution-context '{"Database": "default"}' 
--result-configuration '{"OutputLocation": "s3://amzn-s3-demo-bucket/..."}'
```