pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15458: pg_typeof inconsistency on negative integer constant limits
6+ messages / 5 participants
[nested] [flat]

* BUG #15458: pg_typeof inconsistency on negative integer constant limits
@ 2018-10-24 20:47 PG Bug reporting form <noreply@postgresql.org>
  2018-10-24 20:54 ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Andres Freund <andres@anarazel.de>
  0 siblings, 1 reply; 6+ messages in thread

From: PG Bug reporting form @ 2018-10-24 20:47 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: elprans@gmail.com

The following bug has been logged on the website:

Bug reference:      15458
Logged by:          Elvis Pranskevichus
Email address:      elprans@gmail.com
PostgreSQL version: 11.0
Operating system:   x86_64-pc-linux-gnu
Description:        

There seems to be an inconsistency in how the parser and the integer input
functions interpret the integers at the negative limit (-2 ^ 31 and -2 ^
63):


SELECT pg_typeof(-2147483648);

 pg_typeof
-----------
 integer
(1 row)

But:

SELECT -2147483648::integer;
ERROR:  integer out of range


The same issue applies to int8 as well.

PG_INT32_MIN is explicitly defined as -(2 ^ 31 - 1), and it seems 
inconsistent that the parser does not respect that when determining the 
type of numeric constants.



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits
  2018-10-24 20:47 BUG #15458: pg_typeof inconsistency on negative integer constant limits PG Bug reporting form <noreply@postgresql.org>
@ 2018-10-24 20:54 ` Andres Freund <andres@anarazel.de>
  2018-10-24 20:58   ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Elvis Pranskevichus <elprans@gmail.com>
  2018-10-26 06:02   ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 2 replies; 6+ messages in thread

From: Andres Freund @ 2018-10-24 20:54 UTC (permalink / raw)
  To: elprans@gmail.com; pgsql-bugs@lists.postgresql.org

Hi,

On 2018-10-24 20:47:21 +0000, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      15458
> Logged by:          Elvis Pranskevichus
> Email address:      elprans@gmail.com
> PostgreSQL version: 11.0
> Operating system:   x86_64-pc-linux-gnu
> Description:        
> 
> There seems to be an inconsistency in how the parser and the integer input
> functions interpret the integers at the negative limit (-2 ^ 31 and -2 ^
> 63):
> 
> 
> SELECT pg_typeof(-2147483648);
> 
>  pg_typeof
> -----------
>  integer
> (1 row)
> 
> But:
> 
> SELECT -2147483648::integer;
> ERROR:  integer out of range

> 
> The same issue applies to int8 as well.
> 
> PG_INT32_MIN is explicitly defined as -(2 ^ 31 - 1), and it seems 
> inconsistent that the parser does not respect that when determining the 
> type of numeric constants.

It's just a precedence issue. :: binds with higher precedence, so the
above is actually -(2147483648::integer), rather than
(-2147483648)::integer. Therefore you get an overflow.

Greetings,

Andres Freund




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits
  2018-10-24 20:47 BUG #15458: pg_typeof inconsistency on negative integer constant limits PG Bug reporting form <noreply@postgresql.org>
  2018-10-24 20:54 ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Andres Freund <andres@anarazel.de>
@ 2018-10-24 20:58   ` Elvis Pranskevichus <elprans@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Elvis Pranskevichus @ 2018-10-24 20:58 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-bugs@lists.postgresql.org

On Wednesday, October 24, 2018 4:54:32 PM EDT Andres Freund wrote:
> Hi,
> 
> On 2018-10-24 20:47:21 +0000, PG Bug reporting form wrote:
> > The following bug has been logged on the website:
> > 
> > Bug reference:      15458
> > Logged by:          Elvis Pranskevichus
> > Email address:      elprans@gmail.com
> > PostgreSQL version: 11.0
> > Operating system:   x86_64-pc-linux-gnu
> > Description:
> > 
> > There seems to be an inconsistency in how the parser and the integer
> > input functions interpret the integers at the negative limit (-2 ^
> > 31 and -2 ^ 63):
> > 
> > 
> > SELECT pg_typeof(-2147483648);
> > 
> >  pg_typeof
> > 
> > -----------
> > 
> >  integer
> > 
> > (1 row)
> > 
> > But:
> > 
> > SELECT -2147483648::integer;
> > ERROR:  integer out of range
> > 
> > 
> > The same issue applies to int8 as well.
> > 
> > PG_INT32_MIN is explicitly defined as -(2 ^ 31 - 1), and it seems
> > inconsistent that the parser does not respect that when determining
> > the type of numeric constants.
> 
> It's just a precedence issue. :: binds with higher precedence, so the
> above is actually -(2147483648::integer), rather than
> (-2147483648)::integer. Therefore you get an overflow.

Ah, you're right.  Sorry for the noise.


                              Elvis






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits
  2018-10-24 20:47 BUG #15458: pg_typeof inconsistency on negative integer constant limits PG Bug reporting form <noreply@postgresql.org>
  2018-10-24 20:54 ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Andres Freund <andres@anarazel.de>
@ 2018-10-26 06:02   ` Fabien COELHO <coelho@cri.ensmp.fr>
  2018-10-26 06:24     ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Andres Freund <andres@anarazel.de>
  1 sibling, 1 reply; 6+ messages in thread

From: Fabien COELHO @ 2018-10-26 06:02 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: elprans@gmail.com, PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>


>> SELECT -2147483648::integer;
>> ERROR:  integer out of range
>
> It's just a precedence issue. :: binds with higher precedence, so the
> above is actually -(2147483648::integer), rather than
> (-2147483648)::integer. Therefore you get an overflow.

The error message may be nicer by expliciting the offending string, and/or 
locating it precisely within the query?

-- 
Fabien.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits
  2018-10-24 20:47 BUG #15458: pg_typeof inconsistency on negative integer constant limits PG Bug reporting form <noreply@postgresql.org>
  2018-10-24 20:54 ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Andres Freund <andres@anarazel.de>
  2018-10-26 06:02   ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Fabien COELHO <coelho@cri.ensmp.fr>
@ 2018-10-26 06:24     ` Andres Freund <andres@anarazel.de>
  2018-10-26 08:17       ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

From: Andres Freund @ 2018-10-26 06:24 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: elprans@gmail.com, PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>

Hi,

On 2018-10-26 08:02:59 +0200, Fabien COELHO wrote:
> 
> > > SELECT -2147483648::integer;
> > > ERROR:  integer out of range
> > 
> > It's just a precedence issue. :: binds with higher precedence, so the
> > above is actually -(2147483648::integer), rather than
> > (-2147483648)::integer. Therefore you get an overflow.
> 
> The error message may be nicer by expliciting the offending string, and/or
> locating it precisely within the query?

Including the string would make the function not leak proof though, so
that seems like a no-go.  Location would be possible, but there's some
architectural issues around doing so at execution time - we only really
have the setup to do so at parse time currently.  Tom was looking to
change that at some point however, iirc.

Greetings,

Andres Freund




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits
  2018-10-24 20:47 BUG #15458: pg_typeof inconsistency on negative integer constant limits PG Bug reporting form <noreply@postgresql.org>
  2018-10-24 20:54 ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Andres Freund <andres@anarazel.de>
  2018-10-26 06:02   ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Fabien COELHO <coelho@cri.ensmp.fr>
  2018-10-26 06:24     ` Re: BUG #15458: pg_typeof inconsistency on negative integer constant limits Andres Freund <andres@anarazel.de>
@ 2018-10-26 08:17       ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2018-10-26 08:17 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Fabien COELHO <coelho@cri.ensmp.fr>; elprans@gmail.com, PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>

Andres Freund <andres@anarazel.de> writes:
> On 2018-10-26 08:02:59 +0200, Fabien COELHO wrote:
>> The error message may be nicer by expliciting the offending string, and/or
>> locating it precisely within the query?

> Including the string would make the function not leak proof though, so
> that seems like a no-go.  Location would be possible, but there's some
> architectural issues around doing so at execution time - we only really
> have the setup to do so at parse time currently.  Tom was looking to
> change that at some point however, iirc.

Yeah.  That project was on hold till you got done whacking expression
execution around; but if that's about finished, I might take another look.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2018-10-26 08:17 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-10-24 20:47 BUG #15458: pg_typeof inconsistency on negative integer constant limits PG Bug reporting form <noreply@postgresql.org>
2018-10-24 20:54 ` Andres Freund <andres@anarazel.de>
2018-10-24 20:58   ` Elvis Pranskevichus <elprans@gmail.com>
2018-10-26 06:02   ` Fabien COELHO <coelho@cri.ensmp.fr>
2018-10-26 06:24     ` Andres Freund <andres@anarazel.de>
2018-10-26 08:17       ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox