Trying to order by multiple fields

#1

I want to order by timestamp. But if the timestamps are the same, I want to order by another value i.e. version number. Is this possible?

I’m expecting something like @db(order=‘descending(toUTC(timestamp)), descending(verNum)’)

1 Like

#2

yes it is possible, and the way you are expecting the definition is correct.

0 Likes

#3

From FetchSpec.c3typ

/**

  • Specifies the order to return Objs. Default if not specified is by “id”.
  • Supports multiple fields (e.g. “field1, field2”) and descending order per field (e.g. “field1, descending(field2)”).
  • If {@link limit} is set to -1, and order is specified as “”, then no order will be applied at the database.
  • This should only be done if its impact is fully understood as it may help performance in some cases and hurt it in
  • others. If you aren’t sure, DON’T USE IT.
    */
    order: long string
0 Likes

#4

Also, you no longer need to use “toUTC”. That was required in Oracle based on the way we indexed timestamps but is a no-op in Postgres

0 Likes