Re: a row disapearing

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: a row disapearing
Date: 2006-05-27 18:06:41
Message-ID: 200605271806.k4RI6fg05177@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rafal Pietrak wrote:
> Hi All,
>
> This is ambarasing, but I've just noticed the following (which looks
> inconsistant to inexperienced eye). Having a table:
>
> test=> CREATE TABLE xxx (id int, info text);
>
> With some rows in it, I try:
>
> test=> SELECT count(1) from xxx where id=1;
> count
> -------
> 0
> (1 row)
>
> This is correct (meaning, I expected that). But when I try to fetch the
> actual selector used in the query as well, I get no rows instead.
>
> test=> SELECT count(1),id from xxx where id=1 group by id;
> count | id
> -------+----
> (0 rows)
>
> Is this a feature, or a bug? And in fact, is there a construct to get
> both the count() and its selectors *in*case*, when the count is ZERO?
>
> All the above in postgres 8.1.

It is supposed to work that way. In the first query, we have to return
a row to show you the count, while in the second query, there is no 'id'
value to show you, so we return nothing (nothing to GROUP BY).

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rafal Pietrak 2006-05-27 18:19:48 Re: a row disapearing
Previous Message Rafal Pietrak 2006-05-27 18:01:56 a row disapearing