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

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Michael Richards <miker(at)scifair(dot)acadiau(dot)ca>
Cc: sql(at)postgreSQL(dot)org, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Counting bool flags in a complex query
Date: 1999-07-14 16:13:39
Message-ID: 378CB733.EFBCA98F@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> 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?

Try

select sum(case when bfield = TRUE then 1 else 0 end) from table;

It works for me...

- Thomas

--
Thomas Lockhart lockhart(at)alumni(dot)caltech(dot)edu
South Pasadena, California

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 1999-07-14 16:17:52 Re: [HACKERS] Interesting behaviour !
Previous Message Tom Lane 1999-07-14 16:02:08 Re: [HACKERS] MAX Query length