Skip to content

Commit 520a557

Browse files
committed
Minor - Adding params to start query execution
1 parent 89ab547 commit 520a557

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

awswrangler/athena/_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ def start_query_execution(
410410
workgroup: Optional[str] = None,
411411
encryption: Optional[str] = None,
412412
kms_key: Optional[str] = None,
413+
params: Optional[Dict[str, Any]] = None,
413414
boto3_session: Optional[boto3.Session] = None,
414415
data_source: Optional[str] = None,
415416
) -> str:
@@ -434,6 +435,10 @@ def start_query_execution(
434435
None, 'SSE_S3', 'SSE_KMS', 'CSE_KMS'.
435436
kms_key : str, optional
436437
For SSE-KMS and CSE-KMS , this is the KMS key ARN or ID.
438+
params: Dict[str, any], optional
439+
Dict of parameters that will be used for constructing the SQL query. Only named parameters are supported.
440+
The dict needs to contain the information in the form {'name': 'value'} and the SQL query needs to contain
441+
`:name;`. Note that for varchar columns and similar, you must surround the value in single quotes.
437442
boto3_session : boto3.Session(), optional
438443
Boto3 Session. The default boto3 session will be used if boto3_session receive None.
439444
data_source : str, optional
@@ -457,6 +462,10 @@ def start_query_execution(
457462
>>> query_exec_id = wr.athena.start_query_execution(sql='...', database='...', data_source='...')
458463
459464
"""
465+
if params is None:
466+
params = {}
467+
for key, value in params.items():
468+
sql = sql.replace(f":{key};", str(value))
460469
session: boto3.Session = _utils.ensure_session(session=boto3_session)
461470
wg_config: _WorkGroupConfig = _get_workgroup_config(session=session, workgroup=workgroup)
462471
return _start_query_execution(

0 commit comments

Comments
 (0)