How to Add a Column in DynamoDB

后端 未结 4 1296
無奈伤痛
無奈伤痛 2021-01-31 00:47

Is there a way to add a new column to existing table in DynamoDB in Amazon\'s AWS?

Google didn\'t help,

UpdateTable Query in http://docs.aws.amazon.com/cli/lat

相关标签:
4条回答
  • 2021-01-31 01:32

    DynamoDB does not require schema definition, and so there is no such thing as a "column". You can just add a new item with a new attribute.

    0 讨论(0)
  • 2021-01-31 01:37

    A way to add a new column to existing table in DynamoDB in Amazon's AWS:

    We can store the values in DynamoDb in 2 ways, (i) In an RDBMS Type of Structure for the DynamoDB, we can add a new Coulmn by executing the same command keeping the "new Column" entry within which the Records in the Existing Table has been created. we can use DynamoDb with the Records/ Rows having Values for certain Columns while other columns does not have Values.

    (ii) In a NoSQL kind of Structure; where we store a Json String within a Column to keep all the attributes as per the Requirement. Here we are generating a json string and we have to add the new Attribute into the json String which can then be inserted into the same Column but with the new Attribute.

    0 讨论(0)
  • 2021-01-31 01:46

    I installed NoSQL Workbench then connected to existing DynamoDB Table and tried to update existing Item by adding a new attribute. I figured out that we can only add a new attribute with one of these types - "SS", "NS", "BS" (String Set, Number Set, Binary Set"). In Workbench, we can generate code for the chosen operation.

    I scanned my dynamodb Table and for each item added new attribute with type "SS" then I scanned again and updated recently added new attribute to type - "S" in order create a global secondary index (GSI) with a primary key - "pk2NewAttr".

    NoSQL Workbench related video - https://www.youtube.com/watch?v=Xn12QSNa4RE&feature=youtu.be&t=3666

    Example in Python "how to scan all dynamodb Table" - https://gist.github.com/pgolding

    0 讨论(0)
  • 2021-01-31 01:52

    Well, let's not get dragged away in the semantic discussion about the difference between "fields" and "columns". The word "column" does remind us of relational databases, which dynamodb is not. In essence that means that dynamodb does not have foreign keys.

    Dynamodb does have "primary partition keys" and "index partition keys" though, just as with relational databases.

    You do need to respect those keys when you add data. But aside from those requirements, you don't have to predefine your fields (except for those partition keys mentioned earlier).

    Assuming that you are new to this, some additional good practices:

    • Add a numeric field to each record, to store the time of creation in seconds. Dynamodb has optional cleaning features, which require this type of field in your data.
    • You cannot use dates in dynamodb, so you have to store those as numeric fields or as strings. Given the previously mentioned remark, you may to prefer a numeric type for them.
    • Don't store big documents in it, because there is a maximum fetch size of 16MB, and a maximum record size of 400KB. Fortunately, AWS has a DocumentDB as well.
    0 讨论(0)
提交回复
热议问题