AWS CLI を使用して、プリペアドステートメントを作成する
AWS CLI を使用してプリペアドステートメントを作成するには、次のいずれかの athena コマンドを使用できます。
-
create-prepared-statementコマンドを使用して、実行パラメータを持つクエリステートメントを指定します。 -
start-query-executionコマンドを使用して、PREPARE構文を使用するクエリ文字列を指定します。
create-prepared-statement を使用する
次の例のように、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 構文を使用する
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/..."}'