Home > Software design >  DynamoDB Unique list of elements across all records
DynamoDB Unique list of elements across all records

Time:04-25

I have a simple table that stores list of names for a particular record. I want to ensure that a name can never be used for any other record more than once. The names column should also not be empty; there should always be at least 1 given name.

|          ID           |          Names                                 |
|-----------------------|------------------------------------------------|
|          111          |          [john, bob]                           |
|          222          |          [tim]                                 |
|          333          |          [bob] (invalid bob already used)      |

CodePudding user response:

Easiest solution I believe for this case is to simply use a 2nd table for the values you are interested in being the primary key. Then in application code, simply check that new table if they exist or not to determine if you should create a new record in the primary table. For a List[L] this simply avoids having to traverse every single list of every record to determine if a particular scalar value already exists or not. Credit to Tamas.

enter image description here

https://advancedweb.hu/how-to-properly-implement-unique-constraints-in-dynamodb/

CodePudding user response:

Here’s a blog post describing how to best enforce uniqueness constraints: https://aws.amazon.com/blogs/database/simulating-amazon-dynamodb-unique-constraints-using-transactions/

  • Related