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

Aleksander Alekseev <aleksander@timescale.com>

From: Aleksander Alekseev <aleksander@timescale.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>, Peter Eisentraut <peter@eisentraut.org>, Alvaro Herrera <alvherre@alvh.no-ip.org>, Michael Paquier <michael@paquier.xyz>
Date: 2025-01-24T13:00:29Z
Lists: pgsql-hackers

Attachments

Hi Dean,

> IMO big-endian is the most convenient byte-ordering to use here,
> because then the string representation of the bytea is consistent with
> the hex representation of the integer. It's also consistent with the
> integer-to-bit casts, which output the most significant bits first,
> starting with the sign bit.
>
> As far as the docs go, it's important to document precisely what
> format is used, but I don't think it needs to explain why that choice
> was made. It should also mention the size of the result and that it's
> the two's complement representation, since there are other possible
> representations of integers. So I think it would be sufficient for the
> initial paragraph to say something like "Casting an integer to a bytea
> produces 2, 4, or 8 bytes, depending on the width of the integer type.
> The result is the two's complement representation of the integer, with
> the most significant byte first.", and then list the examples to
> demonstrate that.

Thank you. Here is the corrected patch.

--
Best regards,
Aleksander Alekseev

Commits

  1. Allow casting between bytea and integer types.