You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andre Lomonaco <an...@gmail.com> on 2010/07/25 00:19:06 UTC
Using SQL ABS
Hi Everyone,
I'm newbie in Cayenne and I will apreciate if someone can help me in one question..
I have a table with a VARIACAO Field (Type DOUBLE)
I can store in this Field Positive and Negative Numbers
When I execute the following code, it's return to me first the Negative values and after the Positive values
SelectQuery query = new SelectQuery(RiscoTotal.class);
query.addOrdering(RiscoTotal.VARIACAO_PROPERTY,true);
ObjectContext context = BaseContext.getThreadObjectContext();
List<RiscoTotal> riscoTotal = context.performQuery(query);
Return: -12.0, -6.0, 3.0, 15.0
My questions is:
How can I do to make a query to return only the ABS value
I wanna receive the following results
15.0, -12.0, -6.0, -3.0
My Best Regards,
Andre Lomonaco
Re: Using SQL ABS
Posted by Andrus Adamchik <an...@objectstyle.org>.
Unfortunately neither SelectQuery nor EJBQLQuery support functions in
the ORDER BY clause (something we should probably address in 3.1). You
have a few choices:
* Use SQLTemplate
* Map an extra attribute in RiscoTotal DbEntity as "ABS(VARIACAO)",
then an attribute in ObjEntity connected to "ABS(VARIACAO)"
DbAttribute. Then you can order on this fake attribute. (I know you
can map this, but I haven't tried running queries with such mapping. I
guess that should work).
Andrus
On Jul 25, 2010, at 1:19 AM, Andre Lomonaco wrote:
> Hi Everyone,
>
> I'm newbie in Cayenne and I will apreciate if someone can help
> me in one question..
>
> I have a table with a VARIACAO Field (Type DOUBLE)
> I can store in this Field Positive and Negative Numbers
>
> When I execute the following code, it's return to me first the
> Negative values and after the Positive values
>
> SelectQuery query = new SelectQuery(RiscoTotal.class);
> query.addOrdering(RiscoTotal.VARIACAO_PROPERTY,true);
>
> ObjectContext context = BaseContext.getThreadObjectContext();
> List<RiscoTotal> riscoTotal = context.performQuery(query);
>
> Return: -12.0, -6.0, 3.0, 15.0
>
> My questions is:
>
> How can I do to make a query to return only the ABS value
> I wanna receive the following results
>
> 15.0, -12.0, -6.0, -3.0
>
> My Best Regards,
>
> Andre Lomonaco