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

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: [PATCH] Add get_bytes() and set_bytes() functions
Дата
Msg-id 1f3b5d1a-3c6a-497d-9146-431a10db71ee@eisentraut.org
обсуждение исходный текст
Ответ на [PATCH] Add get_bytes() and set_bytes() functions  (Aleksander Alekseev <aleksander@timescale.com>)
Ответы Re: [PATCH] Add get_bytes() and set_bytes() functions
Список 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.



В списке pgsql-hackers по дате отправления: