4

What is the storage space for a number type in DynamoDB Number vs string type?

Say I have a number (1234789). If I store it as number type, then it will take just 4 bytes, and as string it will take 7 bytes?

Does DynamoDB stores all numbers as bigdecimal?

Alexander Patrikalakis
  • 5,054
  • 1
  • 30
  • 48
user1846749
  • 2,165
  • 3
  • 23
  • 36

2 Answers2

1

DynamoDb is a managed cloud service, so I think the way that they store data internally is not clear.

However, they transfer Numbers as Strings for language compatibility support and one of the things that affect RCU/WCU is transfer data size.

So, as far as your concern is about calculating provisioned throughput and costs, Number size should be considered as a String size.

zx485
  • 28,498
  • 28
  • 50
  • 59
iman
  • 199
  • 1
  • 14
0

As Per DynamoDB Documentation : Datatypes :

String

Strings are Unicode with UTF-8 binary encoding. The length of a string must be greater than zero, and is constrained by the maximum DynamoDB item size limit of 400 KB.

If you define a primary key attribute as a string type attribute, the following additional constraints apply:

  1. For a simple primary key, the maximum length of the first attribute value (the partition key) is 2048 bytes.
  2. For a composite primary key, the maximum length of the second attribute value (the sort key) is 1024 bytes.

Number

Numbers can be positive, negative, or zero. Numbers can have up to 38 digits precision—exceeding this will result in an exception.

  1. Positive range: 1E-130 to 9.9999999999999999999999999999999999999E+125
  2. Negative range: -9.9999999999999999999999999999999999999E+125 to -1E-130

In DynamoDB, numbers are represented as variable length. Leading and trailing zeroes are trimmed.

All numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and libraries. However, DynamoDB treats them as number type attributes for mathematical operations.

Note : If number precision is important, you should pass numbers to DynamoDB using strings that you convert from number type.

I Hope, this may help you get your answer.

LuFFy
  • 8,799
  • 10
  • 41
  • 59