You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by Stephen Rufle <sr...@salmonllc.com> on 2010/04/07 15:11:48 UTC

Sorting a string column as a number

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.

Re: Sorting a string column as a number

Posted by Hans Bakker <ma...@antwebsystems.com>.
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.


Re: Sorting a string column as a number

Posted by Stephen Rufle <sr...@salmonllc.com>.
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
srufle@salmonllc.com
H1:480-626-8022
H2:480-802-7173
Yahoo IM: stephen_rufle
AOL IM: stephen1rufle


Re: Sorting a string column as a number

Posted by Bob Morley <rm...@emforium.com>.

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.
-- 
View this message in context: http://n4.nabble.com/Sorting-a-string-column-as-a-number-tp1754297p1755937.html
Sent from the OFBiz - User mailing list archive at Nabble.com.