Re: BUG #15071: Error in PostgreSQL-specific :: type cast - Mailing list pgsql-bugs

From Daniel Gustafsson
Subject Re: BUG #15071: Error in PostgreSQL-specific :: type cast
Date
Msg-id 315DAB2D-4D2A-4556-8941-036784005F98@yesql.se
Whole thread Raw
In response to BUG #15071: Error in PostgreSQL-specific :: type cast  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #15071: Error in PostgreSQL-specific :: type cast  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
> On 16 Feb 2018, at 12:57, PG Bug reporting form <noreply@postgresql.org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference:      15071
> Logged by:          Yuriy Beliy
> Email address:      whiteman.kr@gmail.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

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15071: Error in PostgreSQL-specific :: type cast
Next
From: Tom Lane
Date:
Subject: Re: BUG #15071: Error in PostgreSQL-specific :: type cast