Re: [HACKERS] Counting bool flags in a complex query

From: Michael Richards <miker(at)scifair(dot)acadiau(dot)ca>
To: Duane Currie <dcurrie(at)sandman(dot)acadiau(dot)ca>
Cc: pgsql-hackers(at)hub(dot)org
Subject: Re: [HACKERS] Counting bool flags in a complex query
Date: 1999-07-14 14:51:31
Message-ID: Pine.BSF.4.10.9907141148040.38362-100000@scifair.acadiau.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 14 Jul 1999, Duane Currie wrote:

> > My final problem is to count all the messages with flagnew set to true.
> > The only way I can think to do this is to convert the bool value to a 1 or
> > 0 (which I think should be a standard conversion anyway) and run a sum()
> > on them.
> >
> > Unless anyone can come up with a better way to do this, What is the best
> > way to implement a conversion from bool to int?
>
> Of course, you could always use count() and a 'WHERE flagnew' clause...

Problem with that of course is that by limiting the query with a "where",
I'd lose all the records in the original count, and therefore the total
number of messages (a count that ignores the status of flagnew) would be
wrong.

What I was sort of hoping for was a way to implement a native conversion
from bool to int, and have it included in the standard postgres system. I
think the conversion if a reasonable logical one where true==1 and
false==0. The problem is, I don't have a sweet clue how to do this. I
think it should be a trivial matter to insert something into a system
table...

-Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-07-14 15:01:42 Re: [HACKERS] Updated TODO list
Previous Message Peter Eisentraut 1999-07-14 14:22:13 Re: [HACKERS] Updated TODO list