Thread: Re: Proposal for fixing numeric type-resolution issues

Re: Proposal for fixing numeric type-resolution issues

From
Peter Eisentraut
Date:
Tom Lane writes:

> I expect what you are after is the ability to produce an 0-or-1
> numeric value from a bool field, so that you could do things like
> sum(boolfield::int) to count the number of true values in a column.  
> I agree that we need such an operator (and I'm surprised no one's
> gotten round to contributing one).

Let's contribute one now ...

select count(*) from test4 where a = true;

select sum( case when a then 1 else 0 end ) from test4;


> But I don't agree that there
> should be an implicit, automatic conversion from bool to int; that
> defeats half of the error-checking value of having a separate type for
> truth values in the first place.

Definitely.

-- 
Peter Eisentraut                  Sernanders väg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden