Re: Direct converting numeric types to bool

From: n(dot)zhuchkov(at)postgrespro(dot)ru
To: '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 14:12:20
Message-ID: b0270ceceb68dddaabf4b0824aeaad6c@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for your feedback!
Really, support migration from Oracle isn't the best argumentation for
this patch.
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.
Also in operations with floating-point numbers, may arise a fault in the
results of calculations, because of which the number will always be cast
in true
Thus it sounds like not a bad idea to support direct casting from
numeric types to boolean. What do you think?

Alex Ignatov писал 2018-02-28 18:23:
> -----Original Message-----
> From: n(dot)zhuchkov(at)postgrespro(dot)ru [mailto:n(dot)zhuchkov(at)postgrespro(dot)ru]
> Sent: Wednesday, February 28, 2018 6:04 PM
> To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
> Subject: Direct converting numeric types to bool
>
> Attached patch allow direct convertion of numeric types to bool like
> integer::bool.
> Supported types:
> - smallint;
> - bigint;
> - real;
> - double precision;
> - decimal(numeric).
>
> This functionality is helped with migration from Oracle.
>
> --
> Nikita Zhuchkov
> Postgres Professional: http://www.postgrespro.com The Russian Postgres
> Company
>
> Hello!
>
> What prevent us from:
>
> postgres=# select 1::bigint::int::boolean;
> bool
> ------
> t
> (1 row)
>
> It is just one additional casting and required no additional patching
> --
> Alex Ignatov
> Postgres Professional: http://www.postgrespro.com
> The Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2018-03-26 14:13:38 Re: Re: [HACKERS] GSoC 2017: Foreign Key Arrays
Previous Message Claudio Freire 2018-03-26 14:07:52 Re: [HACKERS] [PATCH] Vacuum: Update FSM more frequently