Re: Proposal for fixing numeric type-resolution issues

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Proposal for fixing numeric type-resolution issues
Дата
Msg-id Pine.LNX.4.21.0005142037410.915-100000@localhost.localdomain
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Jim Mercer
Дата:
Сообщение: broken links on http://www.postgresql.org/doxlist.html
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: Casting, again