eos icon indicating copy to clipboard operation
eos copied to clipboard

How to get single record from table.

Open 26rahulsingh opened this issue 8 years ago • 5 comments

Can anyone help me, I'm trying to get single row (record) from table but get_table_rows api return all the record. how can I get single record based on some condition match from table.

26rahulsingh avatar Nov 22 '18 06:11 26rahulsingh

add -l 1 to your request.

taokayan avatar Nov 22 '18 08:11 taokayan

-l will limit the record but my requirement is to get a single record from table based on condition match. for example - struct = { rows: [{'age': 20, 'name': 'rahul''}, {'age': 18, 'name': 'prachi'}, {'age': 22, 'name': 'ram'}] }; from this table how can i get only row number two. Please elaborate.

26rahulsingh avatar Nov 22 '18 09:11 26rahulsingh

You can only use primary or secondary index to query the table. You can index your search criteria if possible.

taokayan avatar Nov 22 '18 09:11 taokayan

I tried with secondary index but it will sort the data and return full result but i want to get only one record which will match the criteria. How can I do that ?

26rahulsingh avatar Nov 22 '18 10:11 26rahulsingh

If you can convert your criteria to be something sortable and fit into some of the secondary key, then you can still use get_table_rows with limit 1. Otherwise, there's no easy solution to your problem.

taokayan avatar Nov 22 '18 10:11 taokayan