awswrangler.athena.start_query_execution¶
- awswrangler.athena.start_query_execution(sql: str, database: Optional[str] = None, s3_output: Optional[str] = None, workgroup: Optional[str] = None, encryption: Optional[str] = None, kms_key: Optional[str] = None, params: Optional[Dict[str, Any]] = None, boto3_session: Optional[boto3.session.Session] = None, data_source: Optional[str] = None) Any ¶
Start a SQL Query against AWS Athena.
Note
Create the default Athena bucket if it doesn’t exist and s3_output is None. (E.g. s3://aws-athena-query-results-ACCOUNT-REGION/)
Note
This function has arguments which can be configured globally through wr.config or environment variables:
database
workgroup
Check out the Global Configurations Tutorial for details.
- Parameters
sql (str) – SQL query.
database (str, optional) – AWS Glue/Athena database name.
s3_output (str, optional) – AWS S3 path.
workgroup (str, optional) – Athena workgroup.
encryption (str, optional) – None, ‘SSE_S3’, ‘SSE_KMS’, ‘CSE_KMS’.
kms_key (str, optional) – For SSE-KMS and CSE-KMS , this is the KMS key ARN or ID.
params (Dict[str, any], optional) – Dict of parameters that will be used for constructing the SQL query. Only named parameters are supported. The dict needs to contain the information in the form {‘name’: ‘value’} and the SQL query needs to contain :name;. Note that for varchar columns and similar, you must surround the value in single quotes.
boto3_session (boto3.Session(), optional) – Boto3 Session. The default boto3 session will be used if boto3_session receive None.
data_source (str, optional) – Data Source / Catalog name. If None, ‘AwsDataCatalog’ will be used by default.
- Returns
Query execution ID
- Return type
str
Examples
Querying into the default data source (Amazon s3 - ‘AwsDataCatalog’)
>>> import awswrangler as wr >>> query_exec_id = wr.athena.start_query_execution(sql='...', database='...')
Querying into another data source (PostgreSQL, Redshift, etc)
>>> import awswrangler as wr >>> query_exec_id = wr.athena.start_query_execution(sql='...', database='...', data_source='...')