Re: Proposal for fixing numeric type-resolution issues - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Proposal for fixing numeric type-resolution issues
Date
Msg-id Pine.LNX.4.21.0005142037410.915-100000@localhost.localdomain
Whole thread Raw
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Jim Mercer
Date:
Subject: broken links on http://www.postgresql.org/doxlist.html
Next
From: Peter Eisentraut
Date:
Subject: Re: Casting, again