Re: getting max() using SelectQuery

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Feb 04 2004 - 15:23:26 EST

  • Next message: Steve Steinitz: "problem with flattened relationship"

    Hi Stefan,

    Unfortunately you can't use a straight qualifier expression for
    aggregate functions like MAX, MIN, COUNT. Aside from raw SQL, you may
    take a look at this example:
    http://objectstyle.org/cayenne/examples/aggregate-functions/index.html
    . It shows how you can model special entities just for that purpose.
    Examples source code is downloadable separately:
    http://objectstyle.org/cayenne/download.html

    Hope this helps.

    Andrus

    On Feb 4, 2004, at 9:57 AM, Stefan Michel wrote:

    > I want to query the max value of the column number (Long=BIGINT) in
    > table incident .
    > I did manage to get this via raw sql using SqlSelectQuery "SELECT
    > MAX(number) FROM Incident"
    > However would like to get the max value on the object query level.
    >
    > I want something like this:
    > Expression exp=ExpressionFactory.unaryExp(Expression.MAX,
    > IncidentImpl.NUMBER_PROPERTY );
    > SelectQuery query = new SelectQuery(IncidentImpl.class,exp);
    > List data = ctx_.performQuery(query);
    > The above gives the following exception
    > [java] Caused by: org.postgresql.util.PSQLException: ERROR:
    > invalid input syntax for type boolean: "number"
    > [java] at
    > org.postgresql.util.PSQLException.parseServerError(PSQLException.java:
    > 139)
    > (number is a Long on obj level - a BIGINT on DB level - getter and
    > setter are working- the raw max query is working to)
    >
    > Does anyone know how to query the max value on an object level ?
    >
    > The following thread dealt with the same problem, but the proposed
    > solution was a raw sql query:
    > http://www.objectstyle.org/cayenne/lists/cayenne-user/2003/09/0062.html
    >



    This archive was generated by hypermail 2.0.0 : Wed Feb 04 2004 - 15:23:33 EST