Pbm with aggregates on empty output - Mailing list pgsql-bugs

From Jean-Francois Rabasse
Subject Pbm with aggregates on empty output
Date
Msg-id Pine.LNX.4.10.10103061749120.25015-100000@net.lra.ens.fr
Whole thread Raw
Responses Re: Pbm with aggregates on empty output
Re: Pbm with aggregates on empty output
List pgsql-bugs
Hello,
I found a problem. I don't know if it's a bug or a misuse from me.

Here is, in a minimal test version
(I use PostgreSQL 6.5.3 on i686-pc-linux-gnu):

1. A table, even very simple
   => create table thetable ( thevalue int4 );

2. I populate the table with several numeric values...
   => insert into thetable values(1);
   => insert into thetable values(2);
   => insert into thetable values(3);
   => insert into thetable values(4);

3. Now, I want to count my records matching a specified clause.
   My initial idea was to use an aggregate function such as sum

   => select sum(1) from thetable where thevalue > 1;
   sum
   ---
     3
   (1 row)

   It works fine and I just get what I wanted, the records count.

4. If the clause can't be verified, i.e. would generate no output

   => select * from thetable where thevalue > 10000;
   thevalue
   --------
   (0 rows)

   I expected to get a 0 value, for sum().
   In fact, the backend hangs.

   => select sum(1) from thetable where thevalue > 10000;
   pqReadData() -- backend closed the channel unexpectedly.
        This probably means the backend terminated abnormally
        before or while processing the request.
   We have lost the connection to the backend, so further processing is
   impossible.  Terminating.


Please, have you an idea of what's wrong with that ?
Is it a problem in the aggregate processing implementation, when the
select output is empty (or null) ?
Is it legal, for me, to do such thing ?

Thanks in advance...

Jean-Francois Rabasse

--
 Jean-François Rabasse

 Radioastronomie                    e-mail: jean-francois.rabasse@lra.ens.fr
 Département de Physique de l'ENS      tél: +33 (0)1 44 32 25 15
    24,  rue Lhomond                   fax: +33 (0)1 44 32 39 92
 F-75231   PARIS Cedex 05              www: http://www.lra.ens.fr/~rabasse/

pgsql-bugs by date:

Previous
From: Dan McGrath
Date:
Subject: Table restriction problems
Next
From: Peter Eisentraut
Date:
Subject: Re: Using libpq to access a repote database from a c trigger function breaks.