On Mon, 21 Sept 2026 at 15:17, Sehrope Sarkuni <[email protected]> wrote:
>
> On Mon, Sep 21, 2026 at 8:45 AM Matthias van de Meent
> <[email protected]> wrote:
> > On Mon, 21 Sept 2026 at 14:23, Sehrope Sarkuni <[email protected]> wrote:
> > > 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.
>
> Yes, it's possible, but seems clunky and has the extra intermediate
> alloc for the repeat and decode:

Right, but implementing a repeat() for bytea should remove the alloc
and memory scan of decode(), and (IMO) would be a more universally
useful addition.

Do you have a workload in mind that would hit this operation hard
enough that the additional allocs (and function calls) becomes a
significant overhead, or other reasons why overlay's behaviour is
impractical for your workload?

Note, I'm not a huge fan of a 'count' argument in set_byte, as the
function name implies a singular byte being set.


Kind regards,

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

PS, for the reader: Even if it avoids the cost of decode() by using a
direct text-to-bytea binary cast, repeat('\xXX', N)::bytea is not a
good enough solution because that rejects NUL bytes, and won't produce
byteas that are not valid as text (i.e. ones filled with only hex
values 0x80-0xFF).


Reply via email to