英文:
Dynamodb - Query max value
问题
我正在尝试确定用户之前是否创建了交易。
我目前正在使用Python和Boto3查询DynamoDB表。我想查询特定用户的最大时间戳,以确定用户以前是否有交易记录。
类似于select max(timestamp) from transaction where userid = 123
。
这是否可行?
英文:
I'm trying to find out if a user has created a transaction before.
I'm currently using python and boto3 to query a dynamodb table.I would like to query the max timestamp for a specific user to determine if the user has had a transaction before.
Something like select max(timestamp) from transaction where userid = 123
Is this possible?
答案1
得分: 1
只有时间戳是您的DynamoDB表的排序键:
aws dynamodb query \
--table-name my-table \
--key-condition-expression "#pk = :pk" \
--expression-attribute-values '{":pk":{"S":"leeroy"}}' \
--expression-attribute-names '{"#pk":"name"}' \
--no-scan-index-forward \
--limit 1
此Query
将按时间戳返回给定用户的最新项目,效率很高。
英文:
Only if the timestamp is the sort key for your DynamoDB table:
aws dynamodb query \
--table-name my-table \
--key-condition-expression "#pk = :pk" \
--expression-attribute-values '{":pk":{"S":"leeroy"}' \
--expression-attribute-names '{"#pk":"name"}' \
--no-scan-index-forward \
--limit 1
This Query
will return the latest item for a given user by timestamp and is efficient.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论