Re: [PATCH] set_byte() with a count argument - Mailing list pgsql-hackers

From Matthias van de Meent
Subject Re: [PATCH] set_byte() with a count argument
Date
Msg-id CAEze2Wi8Xz3BLW1uwL3UvU08tTAO8Y3y8xvkj6TN3hM63OX4Wg@mail.gmail.com
Whole thread
In response to [PATCH] set_byte() with a count argument  (Sehrope Sarkuni <sehrope@jackdb.com>)
Responses Re: [PATCH] set_byte() with a count argument
List pgsql-hackers
On Mon, 21 Sept 2026 at 14:23, Sehrope Sarkuni <sehrope@jackdb.com> wrote:
>
> Hi hackers,
>
> 0002 adds a four-argument set_byte():
>
>     set_byte(bytes bytea, n integer, newvalue integer, count integer)
>
> setting count consecutive bytes from byte n to newvalue:
>
>     SELECT set_byte('\x0000000000'::bytea, 1, 255, 3);
>     => \x00ffffff00
>
> Today this needs nested set_byte() calls, each copying the whole
> value.  The new form does one copy and one memset().

Doesn't the `overlay(bytea, ...)` function already provide the feature
you're looking for (possibly combined with repeat() for ease of use)?
See https://www.postgresql.org/docs/current/functions-binarystring.html#id-1.5.8.11.5.2.2.6.1.1.1
and/or the ISO SQL spec for its specification.


Kind regards,

Matthias van de Meent
Databricks (https://www.databricks.com)



pgsql-hackers by date:

Previous
From: Aleksander Alekseev
Date:
Subject: Re: Write skew observed under serializable isolation
Next
From: Ilia Evdokimov
Date:
Subject: Re: Optimize MCV stats for sortable types and utilize sorted-order properties