You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Marek Šabo <ms...@buk.cvut.cz> on 2010/09/23 12:35:51 UTC

Sorting strings numerically

Hi,

I would like to know if there is a way to sort string(varchar) columns 
numerically. I know it's bad design but legacy database can't be changed 
atm. I'm talking about IPv4 columns, which we need to sort. ( In new 
model I aim to store them as integers and map extra column in cayenne 
with mysql INET_ATON(), hope it will work.)
I tried to add "+0" to sort order property, but it failed parsing.

Regards,

-- 
Marek Šabo



Re: Sorting strings numerically

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 24/09/10 7:43 AM, Marek Šabo wrote:
> sorry, my first post  was probably confusing.
> I could do it programmatically but I want to know if it is possible with
> cayenne sorting engine, paraphrased, Can I modify sort order property
> for cayenne somehow, e.g. as MySQL function INET_ATON()?
>
> Meanwhile I can create a template query:
>
> SELECT ipAddress FROM Ip4Address ORDER BY
> INET_ATON(Ip4Address.ipAddress)  ASC

There is no such thing as the "cayenne sorting engine". Cayenne does its sorting by creating SQL commands to send to the database. Your approach, sorting in by formula inside the database, is probably the best. It is potentially very slow since I don't think you can create an index on a formula inside mysql.

Ari

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

Re: Sorting strings numerically

Posted by Marek Šabo <ms...@buk.cvut.cz>.
Hi Michael,

sorry, my first post  was probably confusing.
I could do it programmatically but I want to know if it is possible with
cayenne sorting engine, paraphrased, Can I modify sort order property
for cayenne somehow, e.g. as MySQL function INET_ATON()?

Meanwhile I can create a template query:

SELECT ipAddress FROM Ip4Address ORDER BY
INET_ATON(Ip4Address.ipAddress)  ASC

Regards,

-- 
Marek Šabo



On 09/23/2010 11:17 PM, Michael Gentry wrote:
> Hi Marek, are you asking if the database can do it or are you wanting
> to do it in your application's memory with (or without) Cayenne?
>
> mrg
>
> On Thu, Sep 23, 2010 at 6:35 AM, Marek Šabo <ms...@buk.cvut.cz> wrote:
>   
>> Hi,
>>
>> I would like to know if there is a way to sort string(varchar) columns
>> numerically. I know it's bad design but legacy database can't be changed
>> atm. I'm talking about IPv4 columns, which we need to sort. ( In new model I
>> aim to store them as integers and map extra column in cayenne with mysql
>> INET_ATON(), hope it will work.)
>> I tried to add "+0" to sort order property, but it failed parsing.
>>
>> Regards,
>>
>> --
>> Marek Šabo
>>
>>
>>
>>     
>   


Re: Sorting strings numerically

Posted by Michael Gentry <mg...@masslight.net>.
Hi Marek, are you asking if the database can do it or are you wanting
to do it in your application's memory with (or without) Cayenne?

mrg

On Thu, Sep 23, 2010 at 6:35 AM, Marek Šabo <ms...@buk.cvut.cz> wrote:
> Hi,
>
> I would like to know if there is a way to sort string(varchar) columns
> numerically. I know it's bad design but legacy database can't be changed
> atm. I'm talking about IPv4 columns, which we need to sort. ( In new model I
> aim to store them as integers and map extra column in cayenne with mysql
> INET_ATON(), hope it will work.)
> I tried to add "+0" to sort order property, but it failed parsing.
>
> Regards,
>
> --
> Marek Šabo
>
>
>