awswrangler.dynamodb.execute_statement¶
- awswrangler.dynamodb.execute_statement(statement: str, parameters: List[Any] | None = None, consistent_read: bool = False, boto3_session: Session | None = None) Iterator[Dict[str, Any]] | None ¶
Run a PartiQL statement against a DynamoDB table.
- Parameters:
statement (str) – The PartiQL statement.
parameters (Optional[List[Any]]) – The list of PartiQL parameters. These are applied to the statement in the order they are listed.
consistent_read (bool) – The consistency of a read operation. If True, then a strongly consistent read is used. False by default.
boto3_session (Optional[boto3.Session]) – Boto3 Session. If None, the default boto3 Session is used.
- Returns:
An iterator of the items from the statement response, if any.
- Return type:
Optional[Iterator[Dict[str, Any]]]
Examples
Insert an item
>>> import awswrangler as wr >>> wr.dynamodb.execute_statement( ... statement="INSERT INTO movies VALUE {'title': ?, 'year': ?, 'info': ?}", ... parameters=[title, year, {"plot": plot, "rating": rating}], ... )
Select items
>>> wr.dynamodb.execute_statement( ... statement="SELECT * FROM movies WHERE title=? AND year=?", ... parameters=[title, year], ... )
Update items
>>> wr.dynamodb.execute_statement( ... statement="UPDATE movies SET info.rating=? WHERE title=? AND year=?", ... parameters=[rating, title, year], ... )
Delete items
>>> wr.dynamodb.execute_statement( ... statement="DELETE FROM movies WHERE title=? AND year=?", ... parameters=[title, year], ... )