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

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: [PATCH] Add get_bytes() and set_bytes() functions
Date: 2024-08-26 11:31:37
Message-ID: CAJ7c6TNZHsFjELyEYXL5-6uearwMALejx6_seye6c+DaTBw=jw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

> On 19.08.24 16:10, Aleksander Alekseev wrote:
> > To clarify, supporting bytea<->integer (and/or bytea<->numeric) casts
> > doesn't strike me as a terrible idea but it doesn't address the issue
> > I'm proposing to solve.
>
> What is the issue you are proposing to solve?
>
> You linked to a couple of threads and stackoverflow pages, and you
> concluded from that that we should add get_bytes() and set_bytes()
> functions. It's not obvious how you get from the former to the latter,
> and I don't think the functions you propose are well-designed in isolation.

I guess there are in fact two problems, not one.

1. Converting between bytea and integer types
2. Multibyte versions of get_byte() / set_byte()

As you rightly pointed out, for (1) we just need to add missing casts.
Here is the corresponding patch, v3-0001. Note that I couldn't re-use
int{2,4,8}recv because its first argument is StringInfo, so I ended up
implementing my own bytea->int{2,4,8} functions.

I think there may be value in (2) as well. It's implemented in v3-0002
and I did my best to clarify the commit message. On the flip side the
situation when one wants something like extracting int4 from a
bytea(or vice versa) and is not happy with convenience and/or
performance of substr()+casts is arguably rare. I'll be fine with
whatever consensus the community reaches about this patch.

--
Best regards,
Aleksander Alekseev

Attachment Content-Type Size
v3-0001-Allow-casting-between-bytea-and-integer-types.patch application/octet-stream 8.8 KB
v3-0002-Add-get_bytes-and-set_bytes-functions.patch application/octet-stream 9.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alena Rybakina 2024-08-26 11:55:13 Re: Vacuum statistics
Previous Message Jim Jones 2024-08-26 11:28:22 Re: [PATCH] Add CANONICAL option to xmlserialize