Skip site navigation (1) Skip section navigation (2)

Should Aggregate Functions always return one row?

From: wilhelm(dot)pakulla(at)gmx(dot)de
To: pgsql-bugs(at)postgresql(dot)org
Subject: Should Aggregate Functions always return one row?
Date: 2004-01-25 00:33:18
Message-ID: 200401250133.18833.wilhelm.pakulla@gmx.de (view raw or flat)
Thread:
Lists: pgsql-bugs
Hello.

Is this a bug?

>linux=# SELECT * FROM test;
> x
>---
> 1
> 2
> 3
>(3 Rows)
>
>linux=# SELECT * FROM test WHERE FALSE;
> x
>---
>(0 Rows)
>
>phlegma=# SELECT max(x) FROM test WHERE FALSE;
> max
>-----
>
>(1 Rows)
>
>phlegma=#

So, if I use the max() aggregate, I receive one row with the value NULL. Is 
that correct?

My background is the language plpgsql:

I expected to test for the existance of a maximum with
(...)
SELECT INTO e
  max( y ) AS x FROM (table) WHERE (condition);

IF NOT FOUND THEN RETURN; END IF;
(...)

But I have to test with:

(...)
SELECT INTO e
  max( y ) AS x FROM (table) WHERE (condition);

IF e.x IS NULL THEN RETURN; END IF;
(...)

Thanks in advance,
Wilhelm

Responses

pgsql-bugs by date

Next:From: Tom LaneDate: 2004-01-25 02:45:51
Subject: Re: Should Aggregate Functions always return one row?
Previous:From: PostgreSQL Bugs ListDate: 2004-01-24 22:27:22
Subject: BUG #1065: JDBC DataSource Serializability

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group