Subject Re: [firebird-support] Order of Non Order By Records
Author Helen Borrie
At 02:51 PM 5/03/2006, you wrote:
>I have a table that is ordered by a date and a time field. The users
>do not enter the date and time, but they do fill in other information
>on the record. As they do, and after I refresh the view, records with
>the same date and time sometimes seem to be returned in a different
>order.
>
>Is it possible that Firebird is returning the records is a different
>order since it has no instructions to the contrary?

No, it returns them in the requested order. Since you are not
providing anything that allows the rows to be selected on the basis
of "age", all the rows with identical date and time will be in
unpredictable order within their date and time grouping.

>Do I need to
>include the record ID in the "order by" to stop this? For example,
>ORDER BY MyDate,MyTime,MyRecordID?

Only if MyRecordID is accurate for determining "age". Only you know
whether it is or not.

> Is there a better way?

If you want accuracy based on the time when the row was *posted*,
then use a timestamp column, use the 'NOW' context variable (not
CURRENT_TIMESTAMP) and pass it through the UDF GetExactTimestamp from
FbUDF to store the timestamp with 10,000ths of a second accuracy,
e.g., in your trigger

new.MyTimeStamp = GetExactTimestamp(cast('NOW' as timestamp));

Then, when you retrieve them out, use

ORDER BY MyTimestamp

./heLen