Re: Direct converting numeric types to bool - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Direct converting numeric types to bool
Date
Msg-id 26668.1522077222@sss.pgh.pa.us
Whole thread Raw
In response to Re: Direct converting numeric types to bool  (n.zhuchkov@postgrespro.ru)
List pgsql-hackers
n.zhuchkov@postgrespro.ru writes:
> Yes, in postgres already exists int::boolean casting and in case:
> select 10::bigint::int::boolean;
> it will perfectly work. But if you want to cast more significant number:
> select (2^32)::bigint::int::boolean;
> you receive the boundary value error.

Right.  I don't see a reason why we shouldn't create a bigint-to-bool
cast to fix that, and smallint-to-bool maybe for completeness.  However,
I'm less excited about float or numeric to bool, because I don't think
there is any very principled argument about what such a cast should do
with infinities, NaNs, or denormalized numbers.  Somebody who knows
what should happen for their own application can create their own cast
that handles those cases ... but I'm unsure that there's a one-size-
fits-all answer that we could put into a default behavior.

            regards, tom lane


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: bugfifx: a minor mistake in brin_inclusion.c comment
Next
From: Robert Haas
Date:
Subject: Re: Why does load_external_function() return PGFunction?