Re: [PATCH] Add get_bytes() and set_bytes() functions

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Add get_bytes() and set_bytes() functions
Date: 2024-08-16 10:11:18
Message-ID: 1f3b5d1a-3c6a-497d-9146-431a10db71ee@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 14.08.24 13:01, Aleksander Alekseev wrote:
> The proposed patch adds get_bytes() and set_bytes() functions. The
> semantics is similar to get_byte() and set_byte() we already have but
> the functions operate with bigints rather than bytes and the user can
> specify the size of the integer. This allows working with int2s,
> int4s, int8s or even int5s if needed.
>
> Examples:
>
> ```
> SELECT get_bytes('\x1122334455667788'::bytea, 1, 2) = 0x2233;
> ?column?
> ----------
> t
>
> SELECT set_bytes('\x1122334455667788'::bytea, 1, 2, 0xAABB);
> set_bytes
> --------------------
> \x11aabb4455667788
> ```

I think these functions do about three things at once, and I don't think
they address the originally requested purpose very well.

Converting between integers and byte arrays of matching size seems like
reasonable functionality. (You can already do one half of that by
calling int2send(), int4send(), and int8send(), but the other direction
(intXrecv()) is not user-callable).

The other things are extracting that byte array from a larger byte array
and sticking it back into a larger byte array; those seem like separate
operations. There is already substr() for bytea for the first part, and
there might be another string-like operationg for the second part, or
maybe we could add one.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michail Nikolaev 2024-08-16 10:22:00 Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY
Previous Message Heikki Linnakangas 2024-08-16 09:26:28 Re: race condition in pg_class