Re: right() returns the whole string for the most negative n

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>, Ewan Young <kdbase(dot)hack(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: right() returns the whole string for the most negative n
Date: 2026-08-26 12:55:39
Message-ID: CAApHDvrPHJKqUMpqRTUcbb=zBKyfJMWGG0-+nQCQ6Wch6kM+1g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 26 Aug 2026 at 00:33, Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
>
> > On 25 Aug 2026, at 14:18, Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org> wrote:
> >
> > Instead of open-coding this, how about about using pg_neg_s32_overflow?
> >
> > if (pg_neg_s32_overflow(n, &n))
> > n = PG_INT32_MAX;
>
> Yes, that's indeed a good idea.

I do see a few places where we do check for PG_INT32_MIN instead of
using pg_neg_s32_overflow(). The example in [1] does end up with less
code as a result of using pg_neg_s32_overflow(), so it might be worth
removing all applicable examples that use the other method from master
as a follow-up. It'd be worth verifying it doesn't make anything worse
for build systems that don't have __builtin_sub_overflow().

David

[1] https://godbolt.org/z/sfxY847E4

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2026-08-26 12:56:05 Re: Proposal: Conflict log history table for Logical Replication
Previous Message vignesh C 2026-08-26 12:52:03 Re: Proposal: Conflict log history table for Logical Replication