我在Python环境下使用DynamoDB,我想以以下DynamoDB为例:
ID |
时间 |
值 |
1 |
1 1 |
1 |
1 |
2 |
2 3 |
1 |
2 |
4 |
1 |
3 |
4 |
1 |
4 |
6 |
- 我想拥有一个具有唯一 id 和时间(不是 id 或 time )。
- 我想不时放入条目。我希望,如果有相同的 id 和 time 的条目,则PUT操作将失败。
对于第二个标准,我想知道我是否需要先进行 get 操作,否则我可以执行写操作,并且可以通过表设计提出异常,然后我忽略了例外(因为该条目已经存在于DynamoDB中)。
I am using DynamoDB under Python environment and I would like to use the following DynamoDB as an example:
id |
time |
value |
1 |
1 |
1 |
2 |
2 |
3 |
1 |
2 |
4 |
1 |
3 |
4 |
1 |
4 |
6 |
- I would like to have a table that has unique id and time (not id or time).
- I would like to put entries from time to time. I would like the put operation would fail if there is an entry with the same id and time already exist in the table.
For the second criteria, I would like to know if I need to perform a get operation first or I could perform a write operation and, by table design, could raise an exception and then I ignore the exception (because the entry already exist in DynamoDB).
发布评论
评论(1)
您需要让您的代码使用一个分区密钥,该键是ID的复合值,并由诸如哈希(Hash)之类的时间分隔。喜欢
1#1
。您可以使用具有条件表达式的PutItem插入数据,如果PK已经存在,则会失败。
You’ll want to have your code use a partition key that is the compound value of id and time separated by something like a hash. Like
1#1
.You can insert data with a PutItem having a conditional expression to fail if the PK already exists.
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html