Re: Bug #503: case and LIMIT not working together

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: <candrsn(at)mindspring(dot)com>, <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Bug #503: case and LIMIT not working together
Date: 2001-10-30 20:14:44
Message-ID: 20011030120913.Q15016-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


On Tue, 30 Oct 2001 pgsql-bugs(at)postgresql(dot)org wrote:

> Carl Anderson (candrsn(at)mindspring(dot)com) reports a bug with a severity of 2
> The lower the number the more severe it is.
>
> Short Description
> case and LIMIT not working together
>
> Long Description
> PostreSQL 7/1/3 i686-pc-linux-gnu compiled by GCC 3.0
>
> when I count ( case ... ) LIMIT
>
> The count is from the entire table not from the LIMIT
>
> in the below example the count is returned with the
> same value in all three statements
>
> Sample Code
> select count( case when b='T' then 1 else null) from test limit 50;
>
> select count( case when b='T' then 1 else null) from test;
>
> select count(*) from test where b = 'T';

I don't see that this is a bug. Limit affects the output rows. Since
select count() has only one row of output, it seems to me that its
the correct interpretation of the query.

If you want to grab 50 rows and then count on those I think you want
something more like (although I don't know if it works in 7.1):
select count(*) from (select * from test limit 50) t where b='T';

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2001-10-30 20:25:07 Re: Bug #503: case and LIMIT not working together
Previous Message pgsql-bugs 2001-10-30 20:00:21 Bug #505: egpg crashes when using indicator array variables