0
votes

I'm using AWS dynamodb to store some data. This table has 'key' as 'Primary partition key' and 'create_micro_time_float' as 'Primary sort key'.

My data in the table is something like this.

{
    'key': {'S': 'xxx'},
    'create_micro_time_float': {'N': 1499844782.50379992}
}, ...

But when I use 'scan' operation (to retrieve all data in the table), I got something like this.

{
    'key': {'S': 'xxx'},
    'create_micro_time_float': {'N': 1499844782.5037999}
}, ...

The last decimal point of my 'Primary sort key' is missing.

The problem is I want to update all record in the table but now I have an incorrect sort key. I need a correct sort key in order to update the record in the table.

How can I do this (with nodejs dynamodb aws sdk)?

Thank you in advance.

2

2 Answers

0
votes

You can convert to String type before you send as docs says. Using .toFixed() you keep the precision you want.

From AWS Docs

Number

Numbers can be positive, negative, or zero. Numbers can have up to 38 digits precision. Exceeding this results in an exception.

Positive range: 1E-130 to 9.9999999999999999999999999999999999999E+125

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.

0
votes

Since the problem is caused by javascript (js has a limit number length and decimal places), I moved to PHP and use AWS SDK for PHP instead. Now it works!