| От | Tom Lane |
|---|---|
| Тема | Re: Bug #503: case and LIMIT not working together |
| Дата | |
| Msg-id | 2307.1004473507@sss.pgh.pa.us обсуждение |
| Ответ на | Bug #503: case and LIMIT not working together (pgsql-bugs@postgresql.org) |
| Список | pgsql-bugs |
pgsql-bugs@postgresql.org writes:
> case and LIMIT not working together
> 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
> select count( case when b='T' then 1 else null) from test limit 50;
This is not a bug, this is your misunderstanding of what LIMIT does.
LIMIT applies to the output rows of the SELECT it's attached to,
not to the rows scanned to produce the output rows. Since a select
count() will only have one output row, the LIMIT is irrelevant.
In 7.1 and later you can do something like
select count(...) from
(select * from test limit 50) as ss;
to apply the LIMIT before the aggregation step.
regards, tom lane
В списке pgsql-bugs по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера