soldiershin soldiershin - 4 days ago 4
iOS Question

Query to get rows with unique objects parse ios

I have a table called table 1 which contains a field called parent field which contains object(Objectid) of table 2.Now i dont want to get the duplicated objectId's and arrange them on the basis of ascending order.Here is the data of the table.

Table1
parentfield(id)
790112
790000
790001
790112
790000
790001


Now the result would be the first three elements but i dont know the number of id's matched.Is there a way to do that?

Answer

Unfortunately, there is not SELECT DISTINCT / GROUP BY operation in Parse.

See this thread: https://parse.com/questions/retrieving-unique-values

Suggested team solution:

There's no built-in query constraint that would return distinct values based on a column.

As a workaround, you can query for all the rows, then iterate through them and track the distinct values for the desired column

So, the sad, bad, horrible idea, is to make a Cloud Function that fetch all the possible elements ( keep in mind that Parse allow you to fetch at maximum 1000 elements for each query ) and then remove the duplicates from the resulting list. You can do this all on the Cloud code function, and then returning the cleaned list to the client, or you can do this directly on your client devices. All this means that if you want to retrieve the real select distinct equivalent at this conditions, you should first fetch all the element ( a loop of query, retrieving 1000 items at time ) and then apply your custom algorithm for removing the duplicates. I know, it's really long and frustrating, considering the fact that the Parse cloud function execution has a timeout limit of 7-10 seconds. Maybe moving to the Parse backgroud jobs, you can populate a distinct temporary table, since you should have up to 15 minutes of execution before the timeout.

Another drastic solution is to move your data on another server that support an ER databases ( like on Openshift, that keep a free tier ) and with some Parse background job, you synchronize the elements from parse to the ER db, so you redirect the client request to the ER db instead of Parse.

Hope it helps

Comments