I'm using Dynamodb. I have a simple Employee table with fields like id, name, salary, doj, etc. What is the equivalent query of select max(salary) from employee
in dynamodb?
Item size. The maximum item size in DynamoDB is 400 KB, which includes both attribute name binary length (UTF-8 length) and attribute value lengths (again binary length). The attribute name counts towards the size limit.
DynamoDB is a key-value and document database that can support tables of virtually any size with horizontal scaling. This enables DynamoDB to scale to more than ten trillion requests per day with peaks greater than 20 million requests per second, over petabytes of storage.
A single Query operation can retrieve a maximum of 1 MB of data. This limit applies before any FilterExpression or ProjectionExpression is applied to the results. If LastEvaluatedKey is present in the response and is non-null, you must paginate the result set (see Paginating table query results).
If your application reads or writes larger items (up to the DynamoDB maximum item size of 400 KB), it will consume more capacity units.
Not sure about boto3
but inboto
can be run this way
from boto.dynamodb2.table import Table
table = Table("employee")
values = list(table.query_2(reverse=True, limit=1))
MAXVALUE = values[0][salary]
You can model your schema something like:
employee_id
, as partition-keysalary
, as sort-key of the table or local secondary index.Then, Query
your table for given employee_id
, with ScanIndexForward
as false, and pick the first returned entry. Since all rows one employee_id
are stored in sorted fashion, the first entry in desc order will be the one with highest salary
.
You can also keep Limit
as 1, in which case DynamoDB will return only one record.
Relevant documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With