Using the units-function with a value from a table column

Hello!

I have the following query:
[queryBuilder setWhereClause:[NSString stringWithFormat:@“distance( %@, %@, lastLatitude, lastLongitude ) < km(100)”, savedGeoPoint.latitude, savedGeoPoint.longitude]];

And it works like a charm! The distance function saved me from a hell of queries and calculation!
What I would like to do next is use a value from a column of the same table to feed to the km() function like so:
[queryBuilder setWhereClause:[NSString stringWithFormat:@“distance( %@, %@, lastLatitude, lastLongitude ) < km(signalRadius)”, savedGeoPoint.latitude, savedGeoPoint.longitude]];
(signalRadius is an INT)
However, when I try that I get the following error:

FAULT = ‘1055’ [Unknown function ‘km’] <Unknown function ‘km’>

Is this functionality not supported or am I doing something wrong?
If this is not supported - would you consider implementing it?

Thanks!

Hello,
Currently you can only use an integer literal (i.e. a number like 100, 1000 etc.) as an argument to km, mi or other units, but not an integer column.

Hello,

Thanks for answering! Do you plan to add the option to use a value from a column in the future?

There are no such plans yet, but we shall consider it now. I tried to check whether it could be a quick fix and unfortunately it requires some additional underlying work, because the units value is calculated before the request actually goes to database and there’s no way to resolve a column to its value at this stage.

I see! Thanks for checking that!
As an alternative - would it be possible to calculate the value of the units-function instead of using it?
For example if it outputs the distance in meters the query can look like this:
distance( lat, lon, lastLatitude, lastLongitude ) < signalRadius * 1000

As far as I’m concerned, the value of distance is in meters, so your example should work correctly.

I just did a few tests and I think it works correctly. Thanks a lot! :slight_smile: