Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamodb get earliest inserted distinct values from a table

I am using Amazon Dynamodb but do not have much experience. I have Prices table like this:

Id | InsertionDate | ProductName | ShopName | Price

There can be different values with same shopname and productname, (the price and insertion date might be different). e.g

id1 | 2015-12-14T16:41:42 | Cheese 500g | Shop1 | 2.4
id2 | 2015-12-14T15:41:42 | Cheese 500g | Shop1 | 2.2
id3 | 2015-12-14T12:41:42 | Cheese 500g | Shop2 | 2.1
id4 | 2015-11-14T12:41:42 | Cheese 500g | Shop2 | 2.5

Now I want to query this table so that I get unique values by shops which are newest (i.e the insertion date is earliest) sorted by price. So from above example I want to get this:

id3 | 2015-12-14T12:41:42 | Cheese 500g | Shop2 | 2.1 
id1 | 2015-12-14T16:41:42 | Cheese 500g | Shop1 | 2.4

Any ideas how to do this?

like image 593
Kote Avatar asked Oct 15 '25 14:10

Kote


1 Answers

you cant do it.

you can query dynamodb only on his indexes (hash-range keys, or global secondary keys.)

in order to query dynamodb, you need at least to query on your 'hash' key, and you will get ordered results on your range key (if you have range key)

http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/Welcome.html

http://www.allthingsdistributed.com/2013/12/dynamodb-global-secondary-indexes.html

like image 91
Eyal Ch Avatar answered Oct 18 '25 17:10

Eyal Ch