realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

where in throws : Unsupported comparison between type 'uuid' and type 'string' #7709

Open amer-zk opened 1 year ago

amer-zk commented 1 year ago

Problem

I have UUID as primary key in my class

I want to make this query:

UUID[] values = new UUID[]{ UUID.fromString(key1) }; query.in("uuid_field" , values);

exception will thrown : Unsupported comparison between type 'uuid' and type 'string'

how can i acheive that ?

JAVA - android studio , realm DB

Solution

No response

Alternatives

No response

How important is this improvement for you?

I'd like to see it, but have a workaround

rorbech commented 1 year ago

Hi @amer-zk. There is currently no way to use in with non-primitive types, so you would have to build the query manually with something like

RealmQuery<...> query = realm.where(....).beginGroup();
Boolean first = true;
for (UUID uuid : uuids) {
    if (first) {
        first = false;
    } else {
        query.or();
    }
    query.equalTo("uuid_field", uuid);
}
query.endGroup();
amer-zk commented 1 year ago

Hi @amer-zk. There is currently no way to use in with non-primitive types, so you would have to build the query manually with something like

RealmQuery<...> query = realm.where(....).beginGroup();
Boolean first = true;
for (UUID uuid : uuids) {
    if (first) {
        first = false;
    } else {
        query.or();
    }
    query.equalTo("uuid_field", uuid);
}
query.endGroup();

i think thats will lead to performance issue ! it must be optimized to excute without loops!

rorbech commented 1 year ago

We just recently added support for querying with multiple values in the underlying core implementation but haven't adopted this in the SDK yet. We are currently focusing on getting features into the Realm Kotlin SDK so you can track the adoption of this in https://github.com/realm/realm-kotlin/issues/929. To fully cover your use case we would also need support for type coercion as part of the query engine. That will most probably be handled as part of https://github.com/realm/realm-kotlin/issues/587.