Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions
Sergey Prokhorenko <sergeyprokhorenko@yahoo.com.au>
From: Sergey Prokhorenko <sergeyprokhorenko@yahoo.com.au>
To: pgsql-hackers <pgsql-hackers@postgresql.org>, Aleksander Alekseev <aleksander@tigerdata.com>
Cc: Andrey Borodin <x4mmm@yandex-team.ru>, Masahiko Sawada <sawada.mshk@gmail.com>
Date: 2025-10-27T14:03:09Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add base32hex support to encode() and decode() functions.
- 497c1170cb10 19 (unreleased) landed
-
Allow explicit casting between bytea and uuid.
- ba21f5bf8aff 19 (unreleased) landed
-
Add support for base64url encoding and decoding
- e1d917182c19 19 (unreleased) cited
Hi, > > Or providing > > 'uuid_encode(uuid, format text) -> text' and 'uuid_decode(text, format > > text) -> uuid' might make sense too, but I'm not sure. > > I like the idea, so I drafted a prototype for discussion. > Though I do not see what else methods should be provided along with added one... I see no reason why we should forbid the use of base32 encoding with bytea. Or have different functions for this e.g. uuid_encode() and encode(). To me it looks like a poor API design. -- Best regards, Aleksander Alekseev ____________________________________________ It seems that bytea is your personal interest, since you continue to impose your bytea when a better solution has already been found with uuid_encode() and uuid_decode(). The bytea proposal has a lot of drawbacks: 1. It requires unnecessary casting in addition to encoding/decoding. This complicates the interface and creates unnecessary cognitive load on developers. It also creates additional CPU load, although perhaps only a small amount. 2. The encoding function encourages developers to use the slightly more compact base64 encoding (see https://www.postgresql.org/docs/current/functions-binarystring.html), which doesn't preserve sort order, isn't URL-safe, is case-sensitive, and requires specifying the case of letters when dictating. This also creates a serious problem of incompatibility between UUID encodings. 3. The hashing functions used by bytea create a temptation to implement popular, idiotic ideas for hashing UUIDs to obscure their creation date and to hide internal keys from clients. 4. Other various functions for bytea allow the construction of Frankenstein identifiers that compete with UUIDv7, which could negatively impact the reputation of UUIDs. The bytea type has nothing in common with the uuid type other than the binary encoding. Therefore, the bytea <-> uuid cast can only encourage abuse and errors, creating the illusion of unlimited developer power. The bytea proposal has no merit whatsoever. It's the worst, most insafe, and most harmful design, undermining efforts to widely adopt UUIDv7 and improve PostgreSQL.