mercredi 2 mars 2016

Obtain record from sqlite by most recent date

I have an Objective-C app that utilizes CoreData and the backing store is a sqlite database.

I'm trying to formulate a query for the FMDatabase to access the most recent record according to the MediaDate.

Here is the table I'm querying, called MediaAccy which has a MediaDate field which is of type timestamp (pictured here)

enter image description here

Here's a query that simply ORDERS the MediaDate field. Notice the ZMEDIADATE field has 2 identical timestamp values, and notice the order of the guids. According to this query, the most recent record has guid 6BBF7...

enter image description here

Now, notice THIS query, where I ask for the record with the MAX date from the given set of records above, and notice the result is for guid 2D8AC... which according to the previous query, that ordered that same data by date, is the 2nd to most recent, not the most recent record.

Will the real most recent record please stand up!

Is timestamp not actually accurate to a precision where it can be sorted, or is there something wrong with the max() function used against a timestamp field?

enter image description here

According to sqlite's documentation for the max() function...

The max() aggregate function returns the maximum value of all values in the group. The maximum value is the value that would be returned last in an ORDER BY on the same column

But according to my results, this isn't what in fact is happening.

Aucun commentaire:

Enregistrer un commentaire