Re: Direct converting numeric types to bool

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: n(dot)zhuchkov(at)postgrespro(dot)ru
Cc: "'pgsql-hackers'" <pgsql-hackers(at)postgresql(dot)org>, Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>
Subject: Re: Direct converting numeric types to bool
Date: 2018-03-26 15:13:42
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

n(dot)zhuchkov(at)postgrespro(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2018-03-26 15:14:03 Re: Why does load_external_function() return PGFunction?
Previous Message Alvaro Herrera 2018-03-26 15:11:26 Re: bugfifx: a minor mistake in brin_inclusion.c comment