HAVING clause - Mailing list pgsql-hackers

From Thomas G. Lockhart
Subject HAVING clause
Date
Msg-id 352B8722.F324CF6C@alumni.caltech.edu
Whole thread Raw
List pgsql-hackers
> Send the bug report to here and Stefan (he is on the TODO list).
> Let's see if he can fix it.

Hi Stefan. I ran across some funny behavior with the HAVING clause:

-- try a having clause in the wrong order (OK, my mistake :)
postgres=> select x.x, count(y.i) from t x, t y
           group by x.x having x.x = 'four';
PQexec() -- Request was sent to backend, but backend closed
 the channel before responding. This probably means the backend
 terminated abnormally before or while processing the request.

<start over>
-- works better when it is a good query...
postgres=> select x.x, count(y.i) from t x, t y
           group by x.x having count(y.i) = 40;
x   |count
----+-----
four|   40
(1 row)

Table is defined below...

                         - Tom


postgres=> create table t (x text, i int);

<populate the table; one entry for 'one', two for 'two', etc>

postgres=> select x, i, count(i) from t group by x, i;
x    |i|count
-----+-+-----
four |4|    4
one  |1|    1
three|3|    3
two  |2|    2
(4 rows)

pgsql-hackers by date:

Previous
From: Maurice Gittens
Date:
Subject: pg_type populated incorrectly in some cases?
Next
From: "Thomas G. Lockhart"
Date:
Subject: HAVING clause