Dynamodb – 查询最大值

huangapple go评论51阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月13日 17:51:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76004042.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定