HAVING clause

Started by Thomas G. Lockhartalmost 28 years ago1 messages
#1Thomas G. Lockhart
lockhart@alumni.caltech.edu

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)