Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch a single column from Realm Database (Android)

I'm a beginner in Realm.

I have a table with 3 columns which named Id, Name, Email,Address. To get the data of Name column, we use a query like 'SELECT Name from table_name' for SQLite.

If we using Realm in Android, then which method do we have to use for fetching the data of only one column?

I searched alot on Google & documentation but to no avail. Could anyone help me?

Update:

What I am tried:

RealmResults<User> results = query.findAll();
ArrayList<String> name = new Arraylist(); 
for(i=0; i<results.size; i++){ 
 name.add(result.get(i).getName();
}

My problem:

results.size()  > 10k. So I want to avoid 10k iteration

for(i=0; i<results.size; i++){ 
}
like image 561
Ranjithkumar Avatar asked Sep 20 '25 15:09

Ranjithkumar


1 Answers

Look at queries section at the documentation:

All fetches (including queries) are lazy in Realm, and the data is never copied.

This mean, that data of particular column (property) will be fetched when you call getMyProperty() method. Not after call of finadAll() method of RealmQuery object

like image 55
Sergey Bubenshchikov Avatar answered Sep 22 '25 06:09

Sergey Bubenshchikov