public inbox for [email protected]  
help / color / mirror / Atom feed
From: Joel Jacobson <[email protected]>
To: David Fetter <[email protected]>
Cc: Aleksander Alekseev <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] Add get_bytes() and set_bytes() functions
Date: Wed, 14 Aug 2024 17:39:32 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <ZrzCpy36C9w/[email protected]>
References: <CAJ7c6TPtOp6+kFX5QX3fH1SVr7v65uHr-7yEJ=GMGQi5uhGtcA@mail.gmail.com>
	<[email protected]>
	<CAJ7c6TNVbeNsxbbj1QJTcjdkHRmJUBfF=iv_dOMDAGxoKY9CyQ@mail.gmail.com>
	<[email protected]>
	<ZrzCpy36C9w/[email protected]>

On Wed, Aug 14, 2024, at 16:43, David Fetter wrote:
>> I also think it would be nice to provide these convenience functions:
>> to_bytes(bigint) -> bytea
>> from_bytes(bytea) -> bigint
>
> Along with these, would it make sense to have other forms of these
> that won't choke at 63 bits, e.g. NUMERIC or TEXT?

I wonder what would be good names for such functions though?

Since NUMERIC can have decimal digits, and since BYTEA can already be casted to
TEXT, which will just be \x followed by the hex digits, maybe such names should
include "integer" or some other word, to indicate what is being returned?

It's already quite easy to convert to NUMERIC though,
for users who are aware of tricks like this:
SELECT ('0x'||encode('\xCAFEBABEDEADBEEF'::bytea,'hex'))::numeric;
       numeric
----------------------
 14627333968688430831
(1 row)

But, I think it would be better to provide functions,
since many users probably have to google+stackoverflow or gpt
to learn such tricks, which are not in the official documentation.

Regards,
Joel






view thread (4+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: [PATCH] Add get_bytes() and set_bytes() functions
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox