Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: a row disapearing


  • From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
  • To: Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com>, pgsql-general(at)postgresql(dot)org
  • Subject: Re: a row disapearing
  • Date: Sat, 27 May 2006 11:51:05 -0700 (PDT)
  • Message-id: <20060527185105(dot)97413(dot)qmail(at)web31814(dot)mail(dot)mud(dot)yahoo(dot)com>

Maybe this my work for you?

CREATE TABLE xxx (id int, info text);
create table xxx_grp ( id int, grp text);

insert INTO xxx_grp values ( 0, 'group0');
insert INTO xxx_grp values ( 1, 'group1');
insert INTO xxx_grp values ( 2, 'group2');

insert into xxx values ( 1, 'test1');
insert into xxx valves ( 2, 'test2a');
insert into xxx values ( 2, 'test2b');

select  count(xxx.id) as cnt, 
        xxx.id, 
        xxx_grp.id as grpid, 
        xxx_grp.grp 
from    xxx 
right join xxx_grp 
on      (xxx.id = xxx_grp.id) 
group by xxx.id, grpid, xxx_grp.grp 
order by xxx_grp.id;

 cnt | id | grpid |  grp
-----+----+-------+--------
   0 |    |     0 | group0
   1 |  1 |     1 | group1
   2 |  2 |     2 | group2


regards,

Richard Broersma Jr.



--- Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com> wrote:

> On Sat, 2006-05-27 at 14:06 -0400, Bruce Momjian wrote:
> > > 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).
> 
> But is there a way to achieve one row output with both the count() and
> its selector, when the ocunt is ZERO?
> 
> I'm digging this, because it looke like I need a VIEW, that returns such
> count() no matter what. And in fact the selector (which is coming from
> subquery) is more important for me in that case, than the count() itself
> (well, I need to distinquish zero from something, but nothing more).
> 
> Is there a way to see it?
> 
> -- 
> -R
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
> 




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group