Realm Arithematic Queries


#1

Hi There Realm users

I wanted to ask if anyone had experienced mathematical and logical queries in Realm?


#2

Realm has aggregate expressions within queries that are ‘mathematical’ - for example, @count, @min, @max, @sum and @avg. Realm also supports OR and AND in queries which are ‘logical’.

Perhaps if you can clarify what you’re asking or provide a use case the question can be better addressed.


#3

This is my InventoryOut Model…

import java.util.UUID;

import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.annotations.PrimaryKey;

public class inventoryOutModel extends RealmObject {

@PrimaryKey
private String id = UUID.randomUUID().toString();

private String outName;
private String outFeild;
private double outQuantity;
private String outDate;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getOutName() {
return outName;
}

public void setOutName(String outName) {
this.outName = outName;
}

public String getOutFeild() {
return outFeild;
}

public void setOutFeild(String outFeild) {
this.outFeild = outFeild;
}

public double getOutQuantity() {
return outQuantity;
}

public void setOutQuantity(double outQuantity) {
this.outQuantity = outQuantity;

}

public String getOutDate() {
return outDate;
}

public void setOutDate(String outDate) {
this.outDate = outDate;
}
}

This is inventoryPresentModel

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;

public class inventoryPresentModel extends RealmObject {

@PrimaryKey
private String id;

private String presentName;

private double presentQuantity;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getPresentName() {
return presentName;
}

public void setPresentName(String presentName) {
this.presentName = presentName;
}

public double getPresentQuantity() {
return presentQuantity;
}

public void setPresentQuantity(double presentQuantity) {
this.presentQuantity = presentQuantity;
}
}

I want to subtract values of quantity like outQUantity - presentQuantity


#4

There is a discussion about this feature here https://github.com/realm/realm-java/issues/6397
In short, arithmetic queries are not yet supported by the java binding, but you can do the work yourself in the app code as a workaround.


#5

@jstone that issue was opened by me…