Re: pgsql 10.19 : "ERROR: cannot convert infinity to numeric" except there is no infinity

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: pgsql 10.19 : "ERROR: cannot convert infinity to numeric" except there is no infinity
Date: 2022-07-19 17:47:00
Message-ID: deb5984f-e293-090a-2fdf-e2b1ae9042e2@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 7/19/22 10:42 AM, Adrian Klaver wrote:
> On 7/19/22 10:32 AM, Adrian Klaver wrote:
>> On 7/19/22 10:26 AM, Achilleas Mantzios wrote:
>
>>
>> Have you tried:
>>
>> NULLIF(cept.value, 'inf')::numeric
>
> That was a miss. I originally tested this on Postgres 14 and of course
> it worked. Trying it on Postgres 12 got:
>
> select nullif(1.5, 'inf')::numeric;
> ERROR:  invalid input syntax for type numeric: "inf"
> LINE 1: select nullif(1.5, 'inf')::numeric;
>
> Due to this:
>
> https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-NULLIF
>
>
> "The two arguments must be of comparable types. To be specific, they are
> compared exactly as if you had written value1 = value2, so there must be
> a suitable = operator available."
>
> So:
>
> 1.5::numeric = 'inf'::numeric

The cheat would be:

select version();
version

-------------------------------------------------------------------------------------
PostgreSQL 12.10 on x86_64-pc-linux-gnu, compiled by gcc (SUSE Linux)
7.5.0, 64-bit

select nullif('inf'::float, 'inf')::numeric;
nullif
--------
NULL

select nullif(1.5::float, 'inf')::numeric;
nullif
--------
1.5
(1 row)

>>
>>>>> --
>>>>> Achilleas Mantzios
>>>>> DBA, Analyst, IT Lead
>>>>> IT DEPT
>>>>> Dynacom Tankers Mgmt
>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2022-07-19 17:51:04 Re: Out Of Memory
Previous Message Adrian Klaver 2022-07-19 17:42:19 Re: pgsql 10.19 : "ERROR: cannot convert infinity to numeric" except there is no infinity