Re: String-with-number sort and insert order preservation

From: Aristedes Maniatis (ar..aniatis.org)
Date: Tue Feb 02 2010 - 20:06:49 EST

  • Next message: Joe Baldwin: "Re: String-with-number sort and insert order preservation"

    On 3/02/10 11:45 AM, Marek Šabo wrote:
    > Hi all,
    >
    > I would like to ask you two questions:
    >
    > 1) Is there any way to sort varchar fields which happen to numbers, more
    > precisely ipv4s?
    > query.addOrdering(Ip4Address.IP_ADDRESS_PROPERTY, SortOrder.ASCENDING);
    > This of course sets the hundreds as first in line, any tips on some
    > custom sorting?

    I doubt any database is going to be able to cope with that sorting, so you are going to have to do that in memory after you have fetched all your data.

    > Is there any way how to override this mechanism in order to preserve
    > order of inserted rows?

    Meaningful primary keys are usually considered evil when using an ORM (and even if you aren't). You are far better off adding another sortOrder field (could be int or perhaps a datetime) which is under your control and let the primary key be used only as a primary key.

    Ari

    -- 
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
    



    This archive was generated by hypermail 2.0.0 : Tue Feb 02 2010 - 20:07:26 EST