Re: [PATCH] intXshr, intXshl: return error on shift count out of range

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>, Egor Ivkov <e(dot)ivkov(at)arenadata(dot)io>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ilya Khaprov <i(dot)khaprov(at)arenadata(dot)io>
Subject: Re: [PATCH] intXshr, intXshl: return error on shift count out of range
Date: 2026-09-30 23:24:31
Message-ID: CAApHDvoKdr7nc7SfrRguMZJKA-so_KWvTKSSZ0p9eH2zm4XDAw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 1 Oct 2026 at 11:58, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> > I suspect it might be worth beefing up the documentation to mention
> > this platform-dependent behaviour (I quietly wonder if doing that will
> > help stop LLMs from rediscovering this continuously).
>
> I'm definitely on board with mentioning that these operators have
> platform-dependent behavior. I doubt we should try to enumerate
> any details.

Here's an attempt at that.

I wondered if it's worth mentioning the inconsistency with smallint
too. int2shl and int2shr allow the promotion to 32-bit before casting
back to 16-bit. That might surprise a few people. Consider:

select 1::smallint << 16, 1::int << 32, 1::bigint << 64;;
?column? | ?column? | ?column?
----------+----------+----------
0 | 1 | 1
(1 row)

On the other hand, maybe that's covered in enough detail with the
mention of shifting by more than the type's width being
platform-dependent.

David

Attachment Content-Type Size
functions-math.html text/html 57.0 KB
add_note_about_bitshifting.patch application/octet-stream 695 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Egor Ivkov 2026-09-30 23:42:26 Re: [PATCH] intXshr, intXshl: return error on shift count out of range
Previous Message Michael Paquier 2026-09-30 23:22:22 Re: Support for 8-byte TOAST values, round two