0

How does one go about iterating a table for the next largest primary key in a table that also has a specific secondary value?

Values to iterate with:

  1. uint64_t last_key_known == 1652645054;
  2. name user_value == User B;

Return row #5 only knowing the above.

row number (just for reference ) uint64_t Primary Key name Secondary Key
1 1652644680 User A
2 1652644682 User A
3 1652645054 User B
4 1652645056 User C
5 1652645059 User B
6 1652645060 User A

1 Answer 1

0

Since it is not possible to query like "where user_value == User B AND Primary Key >= 1652645054 You have a few options:

  1. Use scopes: define your table with user (name) as scope and save each user's records in his scope. this way you will have only 1 primary index. I'm not sure this is relevant for you use case...
  2. query by one of the indexes and iterate over the results. for example, get all records for user B (by the secondary index), and iterate to get the records with primary >= 1652645054. This solution can work only if you don't have many records per each user, as you might hit the cpu limit.
  3. Implement something like in this answer

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.