Re: BUG #15071: Error in PostgreSQL-specific :: type cast

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: whiteman(dot)kr(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15071: Error in PostgreSQL-specific :: type cast
Date: 2018-02-16 13:01:10
Message-ID: 315DAB2D-4D2A-4556-8941-036784005F98@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> On 16 Feb 2018, at 12:57, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 15071
> Logged by: Yuriy Beliy
> Email address: whiteman(dot)kr(at)gmail(dot)com
> PostgreSQL version: 10.1
> Operating system: Windows 10
> Description:
>
> PostgreSQL-specific :: type casts for lowest values of integer types are
> produce "Out of range" errors:
>
> SELECT -32768::smallint
> ^ERROR: smallint out of range

The parser will represents this as the numeric portion, 32768, and a “-“ in an
expression of type AEXPR_OP. When passed to i4toi2(), only the numeric part is
passed and the out of range is due to 32768 > SHRT_MAX (same type of issue for
the other types). Casting from non-numeric, like text for example, to smallint
works since it isn’t parsed into an “-“ expr: '-32768'::smallint;

Applying the “-“ op before passing to the typecast function seems the easy
answer, or passing the “-“ separately (which seems kludgier) This is quite old
code though, so I don’t know how much else that would break?

cheers ./daniel

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2018-02-16 15:29:23 Re: BUG #15071: Error in PostgreSQL-specific :: type cast
Previous Message PG Bug reporting form 2018-02-16 11:57:59 BUG #15071: Error in PostgreSQL-specific :: type cast