You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Vera Filippova <oa...@gmail.com> on 2010/09/09 16:32:51 UTC

result of MAX on empty table is 0

Result of aggregate function MAX is 0 on empty table.
I can find in JPQL reference "If SUM , AVG, MAX, or MIN is used, and there
are no values to which the aggregate function can be applied, the result of
the aggregate function is NULL."

        // The following example will print [0]
        String query = "SELECT MAX(obj.number) FROM " +
Bean.class.getSimpleName() + " obj";
        System.out.print(em.createQuery(query).getResultList().isEmpty());

With openjpa 1.2.1 this example will print [null] as expected.

Thank you
-- 
Vera Filippova

Re: result of MAX on empty table is 0

Posted by Rick Curtis <cu...@gmail.com>.
Vera -

I took a look at this for a minute this morning and it looks like we aren't
working as defined per the spec. If this is something you'd like to see
fixed, please go ahead and open a JIRA.

Below is a snippet of a test case... the max should be null, but is zero.

            Object count = em.createQuery("Select count(p.pk) from Entity1 p
where 1=1").getSingleResult();
            Object max = em.createQuery("Select max(p.pk) from Entity1 p
where 1=1").getSingleResult();
            System.out.println("count:"+count+ " max:"+max);

            > count:0 max:0

Thanks,
Rick

On Tue, Sep 14, 2010 at 9:04 AM, Vera Filippova <oa...@gmail.com> wrote:

> Rick Curtis <cu...@...> writes:
> >
> > Are you asking a question? ... or are you just asserting that it works as
> > defined in the spec?
> >
> > Thanks,
> > Rick
> >
> > On Thu, Sep 9, 2010 at 9:32 AM, Vera Filippova <oa...@...> wrote:
> >
> > > Result of aggregate function MAX is 0 on empty table.
>
> I'm asserting that it returns 0 instead of null. I can see the difference.
>
> Thank you,
> Vera
>
>
>
>
>

Re: result of MAX on empty table is 0

Posted by Vera Filippova <oa...@gmail.com>.
Rick Curtis <cu...@...> writes:
> 
> Are you asking a question? ... or are you just asserting that it works as
> defined in the spec?
> 
> Thanks,
> Rick
> 
> On Thu, Sep 9, 2010 at 9:32 AM, Vera Filippova <oa...@...> wrote:
> 
> > Result of aggregate function MAX is 0 on empty table.

I'm asserting that it returns 0 instead of null. I can see the difference.

Thank you,
Vera





Re: result of MAX on empty table is 0

Posted by Rick Curtis <cu...@gmail.com>.
Are you asking a question? ... or are you just asserting that it works as
defined in the spec?

Thanks,
Rick

On Thu, Sep 9, 2010 at 9:32 AM, Vera Filippova <oa...@gmail.com> wrote:

> Result of aggregate function MAX is 0 on empty table.
> I can find in JPQL reference "If SUM , AVG, MAX, or MIN is used, and there
> are no values to which the aggregate function can be applied, the result of
> the aggregate function is NULL."
>
>        // The following example will print [0]
>        String query = "SELECT MAX(obj.number) FROM " +
> Bean.class.getSimpleName() + " obj";
>        System.out.print(em.createQuery(query).getResultList().isEmpty());
>
> With openjpa 1.2.1 this example will print [null] as expected.
>
> Thank you
> --
> Vera Filippova
>