Sorting a string column as a number

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Sorting a string column as a number

Stephen Rufle-2
Is there a way to sort a list of GenericValue objects by number on a
column that is actually a string representation of a number?

Ex.
I have a party list where the externalId of the rows are
1,2,...,10,11,...,22.
When I query and order by externalId they come back as
1
10
11
2
22

I would like to be able to sort the externalId column as if it were a
number. I thought about after the query adding a column to each
GenericValue in the list, but do not think I can
gvObject.set("columnAsNumber", Integer.valueOf(stringValue)) if the
columnAsNumber does not already exist in the entity definition.
Reply | Threaded
Open this post in threaded view
|

Re: Sorting a string column as a number

hans_bakker
only if they are entered with the same number of digits......

On Wed, 2010-04-07 at 06:11 -0700, Stephen Rufle wrote:

> Is there a way to sort a list of GenericValue objects by number on a
> column that is actually a string representation of a number?
>
> Ex.
> I have a party list where the externalId of the rows are
> 1,2,...,10,11,...,22.
> When I query and order by externalId they come back as
> 1
> 10
> 11
> 2
> 22
>
> I would like to be able to sort the externalId column as if it were a
> number. I thought about after the query adding a column to each
> GenericValue in the list, but do not think I can
> gvObject.set("columnAsNumber", Integer.valueOf(stringValue)) if the
> columnAsNumber does not already exist in the entity definition.
--
Ofbiz on twitter: http://twitter.com/apache_ofbiz
Myself on twitter: http://twitter.com/hansbak
Antwebsystems.com: Quality services for competitive rates.

Reply | Threaded
Open this post in threaded view
|

Re: Sorting a string column as a number

Bob Morley
In reply to this post by Stephen Rufle-2
Stephen Rufle wrote
Is there a way to sort a list of GenericValue objects by number on a
column that is actually a string representation of a number?
The first thing that occurred to me was using a view-entity with a field for your sequence that is a complex alias.  Might have to hunt around, but there may be a function you can apply to the string that will result in a numeric or perhaps this comment from the dtd might shed some light ...

In every SELECT statement, the fields that are normally used are really defined to be expressions.
This means for example that you can supply an expression like (discountPercent * 100) in place of  just a field name.  The complex-alias tag is the Ofbiz way to do this.
Reply | Threaded
Open this post in threaded view
|

Re: Sorting a string column as a number

Stephen Rufle-2
Is there a way to use a function like "toNumber" as part of the
alias/complex-alias structure? I looked in the schema and saw what looks
like only aggregate-functions are allowed.

Example of what I think I want

<alias entity-alias="A" name="externalIdAsNum" function="toNumber" >
*[Some way of saying I want externalId selected for use in the function ]*
  <complex-alias operator="-"> <- seems to require an operator which I
do not think I want
        <complex-alias-field  entity-alias="A" field="externalId"
default-value=""/>
  </complex-alias>
</alias>


Bob Morley wrote:

> Stephen Rufle wrote:
>  
>> Is there a way to sort a list of GenericValue objects by number on a
>> column that is actually a string representation of a number?
>>
>>    
>
> The first thing that occurred to me was using a view-entity with a field for
> your sequence that is a complex alias.  Might have to hunt around, but there
> may be a function you can apply to the string that will result in a numeric
> or perhaps this comment from the dtd might shed some light ...
>
> In every SELECT statement, the fields that are normally used are really
> defined to be expressions.
> This means for example that you can supply an expression like
> (discountPercent * 100) in place of  just a field name.  The complex-alias
> tag is the Ofbiz way to do this.
>  

--
Stephen P Rufle
[hidden email]
H1:480-626-8022
H2:480-802-7173
Yahoo IM: stephen_rufle
AOL IM: stephen1rufle