Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

Поиск
Список
Период
Сортировка
Искать

Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Sergey Prokhorenko <sergeyprokhorenko@yahoo.com.au>
Дата:
Hi pgsql-hackers,

I'm writing to propose adding two new built-in functions to PostgreSQL that provide compact UUID encoding using the base32hex format.

I'm one of the contributors to RFC 9562 (UUIDs) and to the uuidv7() implementations in PostgreSQL and several libraries. I'm writing to express my strong support for a new patch by Andrey Borodin, the developer of the built-in uuidv7() function for PostgreSQL 18. This patch adds two new functions for UUID compact text representation. These functions would be long-awaited additions to PostgreSQL's UUID functionality.

I would like to request the community to review this patch and to consider it for commit.


_______________________________

uuid_to_base32hex ( uuid ) -> text

Encodes a UUID into a 26-character base32hex string (uppercase, no hyphens, without padding), using the alphabet 0123456789ABCDEFGHIJKLMNOPQRSTUV as specified in RFC 4648 (https://datatracker.ietf.org/doc/html/rfc4648#page-10).

To accommodate base32hex encoding (5 bits per character), the 128-bit UUID requires 130 bits total (26 characters * 5 bits). The additional 2 zero bits are appended as padding.

This compact, lexicographically sortable format preserves temporal ordering for UUIDv7, making it ideal for primary keys stored as values in JSON key-value pairs, as well as for URLs, filenames, and other space-constrained contexts.

Example:
uuid_to_base32hex('019535d9-3df7-79fb-b466-fa907fa17f9e'::uuid) -> 06AJBM9TUTSVND36VA87V8BVJO
_______________________________

base32hex_to_uuid ( text ) -> uuid

Decodes a base32hex string back into its original UUID. The input is case-insensitive. Invalid inputs return NULL. The decoding is lossless and produces a bitwise-identical UUID.

Example:
base32hex_to_uuid('06AJBM9TUTSVND36VA87V8BVJO') -> 019535d9-3df7-79fb-b466-fa907fa17f9e
_______________________________

We considered base36 but rejected it due to poor performance. Crockford's Base32 was also rejected due to its lack of native support in standard libraries, making base32hex the most practical choice.



Best regards,
Sergey Prokhorenko


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Дата:
Jelte Fennema-Nio  writes:

> First of all, I'm definitely a proponent of being able to encode UUIDs
> using base32hex in Postgres.
>
> On Mon, 27 Oct 2025 at 23:37, Sergey Prokhorenko
>  wrote:
>>
>> Regarding the proposal to couple UUID encoding with the bytea type
>> through encode()/decode() functions: I understand the appeal of
>> reusing existing infrastructure, but this creates a conceptual
>> mismatch. UUID is a distinct semantic type in PostgreSQL, not merely
>> binary data. The bytea type has existed for decades without base32hex
>> encoding, and that's worked fine, because bytea represents arbitrary
>> binary data, not universally unique identifiers with specific
>> structural properties and needs.
>
> I think by far the first step is to make the encoding of UUIDs in
> different formats possible in Postgres. The way to do so with the
> least API impact (and thus as you noticed, least pushback), would be
> to add base32hex to the list of encoding formats in the encode/decode
> functions. Then combining that with UUID <-> bytea casting (which also
> seems totally reasonable functionality to me), would give you the
> functionality (but not the defaults you want).

+1 for adding casts.

> In a follow up patch I would personally be fine making the API to
> encode UUIDs a bit more friendly. In particular, adding an overload to
> the encode function that takes a UUID instead of a bytea seems
> reasonable to me, i.e. encode(id uuid, format text) -> text

Yeah, this works for encode, but not decode, since the argment types are
the same (text, text) in both cases.

> I'm currently less convinced about a decode_uuid function though. I
> think some perf argument (including some benchmarks) would need to be
> made to convince me of its usefulness. Because purely from an API
> friendliness lens, I feel like decode('...', 'base32hex)::uuid and
> decode_uuid('...', 'base32hex') rank basically the same.

Agreed.

> Once/if an accepted RFC actually defines a default shorter encoding
> for UUIDs we could I would definitely be in favor of adding a
> decode_uuid function with the default encoding configured as a default
> argument. As well as adding the default argument to the uuid encode
> overload function.

If it's just one new form, do we need a separate decode function?  Could
we not just make uuid_in() accept both forms (they're easily
distinguishable by length), like bytea_in accepts both the old escape
format and the new hex format?

And if the new format becomes the standard and want to change the
default output format, we would need a GUC like bytea_output anyway, to
let users control when to make the change.

- ilmari


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Jelte Fennema-Nio <postgres@jeltef.nl>
Дата:
On Tue, 28 Oct 2025 at 12:53, Dagfinn Ilmari Mannsåker
 wrote:
> If it's just one new form, do we need a separate decode function?  Could
> we not just make uuid_in() accept both forms (they're easily
> distinguishable by length), like bytea_in accepts both the old escape
> format and the new hex format?
>
> And if the new format becomes the standard and want to change the
> default output format, we would need a GUC like bytea_output anyway, to
> let users control when to make the change.

Agreed to both of those. This seems too far out to spend much time
discussing now.


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Дата:
Dagfinn Ilmari Mannsåker  writes:

> Jelte Fennema-Nio  writes:
>
>> Then combining that with UUID <-> bytea casting (which also
>> seems totally reasonable functionality to me), would give you the
>> functionality (but not the defaults you want).
>
> +1 for adding casts.

Here's a patch for that.  I'm not 100% confident about the error code
for invalid length, but that was the closest one I could find in
errcodes.txt.

I might do the base32hex encode/decode later, unless someone else beats
me to it.

- ilmari

From 1ef47968fd1852f7a409764db2c4b35f0eb948b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= 
Date: Tue, 28 Oct 2025 16:33:17 +0000
Subject: [PATCH] Allow explicit casting between bytea and UUID

This enables using encode() and decode() to convert UUIDs to and from
alternative formats, such as base64.
---
 src/backend/utils/adt/bytea.c      | 26 ++++++++++++++++++++++++++
 src/include/catalog/pg_cast.dat    |  6 ++++++
 src/include/catalog/pg_proc.dat    |  7 +++++++
 src/test/regress/expected/uuid.out | 15 +++++++++++++++
 src/test/regress/sql/uuid.sql      |  4 ++++
 5 files changed, 58 insertions(+)

diff --git a/src/backend/utils/adt/bytea.c b/src/backend/utils/adt/bytea.c
index 6e7b914c563..e51190d2cb2 100644
--- a/src/backend/utils/adt/bytea.c
+++ b/src/backend/utils/adt/bytea.c
@@ -26,6 +26,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/memutils.h"
 #include "utils/sortsupport.h"
+#include "utils/uuid.h"
 #include "utils/varlena.h"
 #include "varatt.h"
 
@@ -1112,3 +1113,28 @@ int8_bytea(PG_FUNCTION_ARGS)
 {
 	return int8send(fcinfo);
 }
+
+/* Cast bytea -> uuid */
+Datum
+bytea_uuid(PG_FUNCTION_ARGS)
+{
+	bytea	   *v = PG_GETARG_BYTEA_PP(0);
+	int			len = VARSIZE_ANY_EXHDR(v);
+	pg_uuid_t  *uuid;
+
+	if (len != UUID_LEN)
+		ereport(ERROR,
+				errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				errmsg("invalid uuid length"));
+
+	uuid = (pg_uuid_t *) palloc(UUID_LEN);
+	memcpy(uuid->data, VARDATA_ANY(v), UUID_LEN);
+	PG_RETURN_POINTER(uuid);
+}
+
+/* Cast uuid -> bytea; can just use uuid_send() */
+Datum
+uuid_bytea(PG_FUNCTION_ARGS)
+{
+	return uuid_send(fcinfo);
+}
diff --git a/src/include/catalog/pg_cast.dat b/src/include/catalog/pg_cast.dat
index fbfd669587f..913c55ef869 100644
--- a/src/include/catalog/pg_cast.dat
+++ b/src/include/catalog/pg_cast.dat
@@ -348,6 +348,12 @@
 { castsource => 'bytea', casttarget => 'int8', castfunc => 'int8(bytea)',
   castcontext => 'e', castmethod => 'f' },
 
+# Allow explicit coercions between bytea and uuid type
+{ castsource => 'bytea', casttarget => 'uuid', castfunc => 'uuid(bytea)',
+  castcontext => 'e', castmethod => 'f' },
+{ castsource => 'uuid', casttarget => 'bytea', castfunc => 'bytea(uuid)',
+  castcontext => 'e', castmethod => 'f' },
+
 # Allow explicit coercions between int4 and "char"
 { castsource => 'char', casttarget => 'int4', castfunc => 'int4(char)',
   castcontext => 'e', castmethod => 'f' },
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 9121a382f76..110593eb399 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -1199,6 +1199,13 @@
   proname => 'int8', prorettype => 'int8', proargtypes => 'bytea',
   prosrc => 'bytea_int8' },
 
+{ oid => '9880', descr => 'convert uuid to bytea',
+  proname => 'bytea', prorettype => 'bytea', proargtypes => 'uuid',
+  prosrc => 'uuid_bytea' },
+{ oid => '9881', descr => 'convert bytea to uuid',
+  proname => 'uuid', prorettype => 'uuid', proargtypes => 'bytea',
+  prosrc => 'bytea_uuid' },
+
 { oid => '449', descr => 'hash',
   proname => 'hashint2', prorettype => 'int4', proargtypes => 'int2',
   prosrc => 'hashint2' },
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 95392003b86..44f58454d19 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -305,5 +305,20 @@ SELECT uuid_extract_timestamp('11111111-1111-1111-1111-111111111111');  -- null
  
 (1 row)
 
+-- casts
+SELECT '11111111-1111-1111-1111-111111111111'::uuid::bytea;
+               bytea                
+------------------------------------
+ \x11111111111111111111111111111111
+(1 row)
+
+SELECT '\xffffffffffffffffffffffffffffffff'::bytea::uuid;
+                 uuid                 
+--------------------------------------
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+(1 row)
+
+SELECT '\x12345678'::bytea::uuid; -- error
+ERROR:  invalid uuid length
 -- clean up
 DROP TABLE guid1, guid2, guid3 CASCADE;
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index 465153a0341..ef81be93670 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -146,6 +146,10 @@ SELECT uuid_extract_timestamp('017F22E2-79B0-7CC3-98C4-DC0C0C07398F') = 'Tuesday
 SELECT uuid_extract_timestamp(gen_random_uuid());  -- null
 SELECT uuid_extract_timestamp('11111111-1111-1111-1111-111111111111');  -- null
 
+-- casts
+SELECT '11111111-1111-1111-1111-111111111111'::uuid::bytea;
+SELECT '\xffffffffffffffffffffffffffffffff'::bytea::uuid;
+SELECT '\x12345678'::bytea::uuid; -- error
 
 -- clean up
 DROP TABLE guid1, guid2, guid3 CASCADE;
-- 
2.51.1

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Tue, Oct 28, 2025 at 9:41 AM Dagfinn Ilmari Mannsåker
 wrote:
>
> Dagfinn Ilmari Mannsåker  writes:
>
> > Jelte Fennema-Nio  writes:
> >
> >> Then combining that with UUID <-> bytea casting (which also
> >> seems totally reasonable functionality to me), would give you the
> >> functionality (but not the defaults you want).
> >
> > +1 for adding casts.
>
> Here's a patch for that.  I'm not 100% confident about the error code
> for invalid length, but that was the closest one I could find in
> errcodes.txt.

Thank you for the patch. I'll review it.

> I might do the base32hex encode/decode later, unless someone else beats
> me to it.

Andrey has shared his patch for base32hex support before[1]. While it
needs to be updated, it seems to implement sufficient function.

Regards,

[1] https://www.postgresql.org/message-id/6F76FA61-E2DC-44EF-9504-889D9BDB4EBD%40yandex-team.ru

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Jelte Fennema-Nio <postgres@jeltef.nl>
Дата:
On Tue, 28 Oct 2025 at 17:41, Dagfinn Ilmari Mannsåker
 wrote:
> Here's a patch for that.

Looks good to me. Maybe add a test where not every byte is the same though.

> I'm not 100% confident about the error code
> for invalid length, but that was the closest one I could find in
> errcodes.txt.

The errorcode you chose seems acceptable to me, but I think a slightly
more fitting option would be ERRCODE_INVALID_BINARY_REPRESENTATION.
Error codes in postgres are pretty arbitrary though, so either seems
fine to me.


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Дата:
Jelte Fennema-Nio  writes:

> On Tue, 28 Oct 2025 at 17:41, Dagfinn Ilmari Mannsåker
>  wrote:
>> Here's a patch for that.
>
> Looks good to me. Maybe add a test where not every byte is the same though.

Good point. I've replaced them with two randomly generated ones.

>> I'm not 100% confident about the error code
>> for invalid length, but that was the closest one I could find in
>> errcodes.txt.
>
> The errorcode you chose seems acceptable to me, but I think a slightly
> more fitting option would be ERRCODE_INVALID_BINARY_REPRESENTATION.
> Error codes in postgres are pretty arbitrary though, so either seems
> fine to me.

That does seem like a better fit. It's used mainly in recv functions,
which this basically is (but user-callable).

Updated patch attaced.

- ilmari

From 7bb7bba8d1be96783ac45df3178fb613e84c39fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= 
Date: Tue, 28 Oct 2025 16:33:17 +0000
Subject: [PATCH v2] Allow explicit casting between bytea and UUID

This enables using encode() and decode() to convert UUIDs to and from
alternative formats, such as base64.
---
 src/backend/utils/adt/bytea.c      | 26 ++++++++++++++++++++++++++
 src/include/catalog/pg_cast.dat    |  6 ++++++
 src/include/catalog/pg_proc.dat    |  7 +++++++
 src/test/regress/expected/uuid.out | 15 +++++++++++++++
 src/test/regress/sql/uuid.sql      |  4 ++++
 5 files changed, 58 insertions(+)

diff --git a/src/backend/utils/adt/bytea.c b/src/backend/utils/adt/bytea.c
index 6e7b914c563..ff9e46f3015 100644
--- a/src/backend/utils/adt/bytea.c
+++ b/src/backend/utils/adt/bytea.c
@@ -26,6 +26,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/memutils.h"
 #include "utils/sortsupport.h"
+#include "utils/uuid.h"
 #include "utils/varlena.h"
 #include "varatt.h"
 
@@ -1112,3 +1113,28 @@ int8_bytea(PG_FUNCTION_ARGS)
 {
 	return int8send(fcinfo);
 }
+
+/* Cast bytea -> uuid */
+Datum
+bytea_uuid(PG_FUNCTION_ARGS)
+{
+	bytea	   *v = PG_GETARG_BYTEA_PP(0);
+	int			len = VARSIZE_ANY_EXHDR(v);
+	pg_uuid_t  *uuid;
+
+	if (len != UUID_LEN)
+		ereport(ERROR,
+				errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+				errmsg("invalid uuid length"));
+
+	uuid = (pg_uuid_t *) palloc(UUID_LEN);
+	memcpy(uuid->data, VARDATA_ANY(v), UUID_LEN);
+	PG_RETURN_POINTER(uuid);
+}
+
+/* Cast uuid -> bytea; can just use uuid_send() */
+Datum
+uuid_bytea(PG_FUNCTION_ARGS)
+{
+	return uuid_send(fcinfo);
+}
diff --git a/src/include/catalog/pg_cast.dat b/src/include/catalog/pg_cast.dat
index fbfd669587f..913c55ef869 100644
--- a/src/include/catalog/pg_cast.dat
+++ b/src/include/catalog/pg_cast.dat
@@ -348,6 +348,12 @@
 { castsource => 'bytea', casttarget => 'int8', castfunc => 'int8(bytea)',
   castcontext => 'e', castmethod => 'f' },
 
+# Allow explicit coercions between bytea and uuid type
+{ castsource => 'bytea', casttarget => 'uuid', castfunc => 'uuid(bytea)',
+  castcontext => 'e', castmethod => 'f' },
+{ castsource => 'uuid', casttarget => 'bytea', castfunc => 'bytea(uuid)',
+  castcontext => 'e', castmethod => 'f' },
+
 # Allow explicit coercions between int4 and "char"
 { castsource => 'char', casttarget => 'int4', castfunc => 'int4(char)',
   castcontext => 'e', castmethod => 'f' },
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 9121a382f76..110593eb399 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -1199,6 +1199,13 @@
   proname => 'int8', prorettype => 'int8', proargtypes => 'bytea',
   prosrc => 'bytea_int8' },
 
+{ oid => '9880', descr => 'convert uuid to bytea',
+  proname => 'bytea', prorettype => 'bytea', proargtypes => 'uuid',
+  prosrc => 'uuid_bytea' },
+{ oid => '9881', descr => 'convert bytea to uuid',
+  proname => 'uuid', prorettype => 'uuid', proargtypes => 'bytea',
+  prosrc => 'bytea_uuid' },
+
 { oid => '449', descr => 'hash',
   proname => 'hashint2', prorettype => 'int4', proargtypes => 'int2',
   prosrc => 'hashint2' },
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 95392003b86..4b635336606 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -305,5 +305,20 @@ SELECT uuid_extract_timestamp('11111111-1111-1111-1111-111111111111');  -- null
  
 (1 row)
 
+-- casts
+SELECT '5b35380a-7143-4912-9b55-f322699c6770'::uuid::bytea;
+               bytea                
+------------------------------------
+ \x5b35380a714349129b55f322699c6770
+(1 row)
+
+SELECT '\x019a2f859ced7225b99d9c55044a2563'::bytea::uuid;
+                 uuid                 
+--------------------------------------
+ 019a2f85-9ced-7225-b99d-9c55044a2563
+(1 row)
+
+SELECT '\x1234567890abcdef'::bytea::uuid; -- error
+ERROR:  invalid uuid length
 -- clean up
 DROP TABLE guid1, guid2, guid3 CASCADE;
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index 465153a0341..63520d0b640 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -146,6 +146,10 @@ SELECT uuid_extract_timestamp('017F22E2-79B0-7CC3-98C4-DC0C0C07398F') = 'Tuesday
 SELECT uuid_extract_timestamp(gen_random_uuid());  -- null
 SELECT uuid_extract_timestamp('11111111-1111-1111-1111-111111111111');  -- null
 
+-- casts
+SELECT '5b35380a-7143-4912-9b55-f322699c6770'::uuid::bytea;
+SELECT '\x019a2f859ced7225b99d9c55044a2563'::bytea::uuid;
+SELECT '\x1234567890abcdef'::bytea::uuid; -- error
 
 -- clean up
 DROP TABLE guid1, guid2, guid3 CASCADE;
-- 
2.51.2

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Hi,

Thanks for the patch.

> That does seem like a better fit. It's used mainly in recv functions,
> which this basically is (but user-callable).
>
> Updated patch attaced.

Perhaps bytea_uuid() should check the UUID format. Consider the
following example:

SELECT uuid_extract_version('\x019a2f859cedffffb99d9c55044a2563'::bytea::uuid);
 uuid_extract_version
----------------------
                   15

There is no UUID version 15 according to RFC 9562, and the
documentation for uuid_extract_version() says:

"""
Extracts the version from a UUID of the variant described by RFC 9562.
For other variants, this function returns null. For example, for a
UUID generated by gen_random_uuid, this function will return 4.
"""

If I read this correctly, either bytea_uuid() should reject this, or
uuid_extract_version() should be modified to return NULL, or the
documentation for uuid_extract_version() should be altered.

-- 
Best regards,
Aleksander Alekseev


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Hi,

> > Updated patch attaced.
>
> Perhaps bytea_uuid() should check the UUID format. Consider the
> following example:
>
> SELECT uuid_extract_version('\x019a2f859cedffffb99d9c55044a2563'::bytea::uuid);

On the flip side we allow this:

=# select '019a2f85-9ced-ffff-b99d-9c55044a2563' :: uuid;
                 uuid
--------------------------------------
 019a2f85-9ced-ffff-b99d-9c55044a2563

So I guess the patch is fine.

-- 
Best regards,
Aleksander Alekseev


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Дата:
Aleksander Alekseev  writes:

> Hi,
>
> Thanks for the patch.
>
>> That does seem like a better fit. It's used mainly in recv functions,
>> which this basically is (but user-callable).
>>
>> Updated patch attaced.
>
> Perhaps bytea_uuid() should check the UUID format. Consider the
> following example:
>
> SELECT uuid_extract_version('\x019a2f859cedffffb99d9c55044a2563'::bytea::uuid);
>  uuid_extract_version
> ----------------------
>                    15

The UUID input function doesn't do any such validation, so I don't see
why the cast should behave any differently:

# select '019a2f859cedffffb99d9c55044a2563'::uuid;
┌──────────────────────────────────────┐
│                 uuid                 │
├──────────────────────────────────────┤
│ 019a2f85-9ced-ffff-b99d-9c55044a2563 │
└──────────────────────────────────────┘

# select uuid_extract_version('019a2f859cedffffb99d9c55044a2563'::uuid);
┌──────────────────────┐
│ uuid_extract_version │
├──────────────────────┤
│                   15 │
└──────────────────────┘
(1 row)

> There is no UUID version 15 according to RFC 9562, and the
> documentation for uuid_extract_version() says:

There's no version 15 specified _yet_.

> """
> Extracts the version from a UUID of the variant described by RFC 9562.
> For other variants, this function returns null. For example, for a
> UUID generated by gen_random_uuid, this function will return 4.
> """
>
> If I read this correctly, either bytea_uuid() should reject this, or
> uuid_extract_version() should be modified to return NULL, or the
> documentation for uuid_extract_version() should be altered.

Future RFCs could define new versions of this variant, which we should
not reject or pretend don't have a version , just because we haven't
heard of them yet.  In fact, RFC 9562 defines two new versions, v7 and
v8, which by this argument PostgreSQL versions before 18 should reject.

- ilmari


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
Вложения:


> On 28 Oct 2025, at 22:44, Masahiko Sawada  wrote:
> 
> Andrey has shared his patch for base32hex support before[1]. While it
> needs to be updated, it seems to implement sufficient function.

I'd propose something like attached patch. It's on top of Ilmari's v2 patch with small suggestions as a step 2.

Thanks!


Best regards, Andrey Borodin.

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Wed, Oct 29, 2025 at 5:19 AM Andrey Borodin  wrote:
>
>
>
> > On 28 Oct 2025, at 22:44, Masahiko Sawada  wrote:
> >
> > Andrey has shared his patch for base32hex support before[1]. While it
> > needs to be updated, it seems to implement sufficient function.
>
> I'd propose something like attached patch. It's on top of Ilmari's v2 patch with small suggestions as a step 2.
>

I've reviewed the v3 patches, and here are some review comments.

v3-0001 and v3-0002:

-                               errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
-                               errmsg("invalid uuid length"));
+                               (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+                                errmsg("invalid length for UUID"),
+                                errdetail("Expected %d bytes, got
%d.", UUID_LEN, len)));

How about the error message like "invalid input length for type uuid"?
I think "uuid" should be lower case as it indicates PostgreSQL uuid
data type, and it's better to use %s format instead of directly
writing "uuid" (see string_to_uuid() for example).

As for the errdetail message, should we add "bytea" also after "got %d"?

---
+-- casts
+SELECT '5b35380a-7143-4912-9b55-f322699c6770'::uuid::bytea;
+SELECT '\x019a2f859ced7225b99d9c55044a2563'::bytea::uuid;
+SELECT '\x1234567890abcdef'::bytea::uuid; -- error

We already have tests for casting bytes to integer data types in
strings.sql. I suggest moving the casting tests from bytea to uuid
into therel. For the uuid.sql file, we could add a test to verify that
a UUID value remains unchanged when it's cast to bytea and back to
UUID. For example,

SELECT v = v::bytea::uuid as matched FROM gen_random_uuid() v;

---
I think we should update the documentation in the uuid section about
casting data between bytea and uuid. For references, we have a similar
description for bytea and integer[1].

v3-0003:

base32hex_encode() doesn't seem to add '=' paddings, but is it
intentional? I don't see any description in RFC 4648 that we can omit
'=' paddings.

---
I think the patch should add tests not only for uuid data type but
also for general cases like other encodings.

---
In uuid.sql tests, how about adding some tests to check if base32hex
maintains the sortability of UUIDv7 data?

---
I would suggest registering the patches to the next commit fest if not yet.

Regards,

[1] https://www.postgresql.org/docs/devel/functions-binarystring.html

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Илья Чердаков <i.cherdakov.pg@gmail.com>
Дата:
31.10.2025 2:10, Masahiko Sawada wrote:
---
I think we should update the documentation in the uuid section about
casting data between bytea and uuid. For references, we have a similar
description for bytea and integer[1].
Greetings!
I briefly tested the patched version of v3. The implemented 
functionality works correctly.

---
You can also add a case with the error from v3-0002 
"invalid base32hex end sequence" to the tests :

+        ereport(ERROR,
+                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                 errmsg("invalid base32hex end sequence"),
+                 errhint("Input data has non-zero padding bits.")));

---
I agree with Masahiko Sawada; information about conversions
should be added to the documentation.

-- 
Best regards,
Ilya Cherdakov, PostgresPro

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Вложения:
Hi,

> I briefly tested the patched version of v3. The implemented
> functionality works correctly.
>
> ---
> You can also add a case with the error from v3-0002
> "invalid base32hex end sequence" to the tests :
>
> +        ereport(ERROR,
> +                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> +                 errmsg("invalid base32hex end sequence"),
> +                 errhint("Input data has non-zero padding bits.")));
>
> ---
> I agree with Masahiko Sawada; information about conversions
> should be added to the documentation.

Here is the rebased patch.

v4-0001 implements uuid <-> bytea casting
v4-0002 implements base32 encoding/decoding

Unless I missed something, 0001 is ready to be merged.

I only rebased v3 and improved the commit messages, but I didn't
account for Masahiko Sawada's feedback for 0002. Andrey, are you still
working on this or others can pick it up?

The patch is not on the commitfest, so I'm about to add it.

-- 
Best regards,
Aleksander Alekseev

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Вложения:
Hi,

> I only rebased v3 and improved the commit messages, but I didn't
> account for Masahiko Sawada's feedback for 0002. Andrey, are you still
> working on this or others can pick it up?
>
> The patch is not on the commitfest, so I'm about to add it.

Here is patch v5 where I accounted for the previous feedback from
Masahiko Sawada and also made some other changes, see below.

> How about the error message like "invalid input length for type uuid"?
> I think "uuid" should be lower case as it indicates PostgreSQL uuid
> data type, and it's better to use %s format instead of directly
> writing "uuid" (see string_to_uuid() for example).

Makes sense. Fixed.

> As for the errdetail message, should we add "bytea" also after "got %d"?

You probably meant "got %d bytes", not "got %d bytea". I believe the
current message is fine, but maybe native speakers will correct us.

> We already have tests for casting bytes to integer data types in
> strings.sql. I suggest moving the casting tests from bytea to uuid
> into therel.

I disagree on the grounds that there are zero tests related to UUID in
strings.sql; uuid.sql is a more appropriate place for these tests IMO.
However if someone seconds the idea we can easily move the tests at
any time.

> For the uuid.sql file, we could add a test to verify that
> a UUID value remains unchanged when it's cast to bytea and back to
> UUID. For example,
>
> SELECT v = v::bytea::uuid as matched FROM gen_random_uuid() v;

Good point. Added.

> base32hex_encode() doesn't seem to add '=' paddings, but is it
> intentional? I don't see any description in RFC 4648 that we can omit
> '=' paddings.

You are right, both base32 and base32hex should add paddings;
substring() can be used if necessary. Fixed.

> I think the patch should add tests not only for uuid data type but
> also for general cases like other encodings.

Yes, and the good place for these tests would be closer to other tests
for encode() and decode() i.e. strings.sql. Fixed.

While working on it I noticed some inconsistencies between base32hex
implementation and our current implementation of base64. As an
example, we don't allow `=` input:

```
=# SELECT decode('=', 'base64');
ERROR:  unexpected "=" while decoding base64 sequence
```

... while base32hex did. I fixed such inconsistencies too.

> In uuid.sql tests, how about adding some tests to check if base32hex
> maintains the sortability of UUIDv7 data?

Agree. Added.

> I think we should update the documentation in the uuid section about
> casting data between bytea and uuid. For references, we have a similar
> description for bytea and integer[1].

Fair point. Fixed.

-- 
Best regards,
Aleksander Alekseev

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Wed, Feb 18, 2026 at 6:58 AM Aleksander Alekseev
 wrote:
>
> Hi,
>
> > I only rebased v3 and improved the commit messages, but I didn't
> > account for Masahiko Sawada's feedback for 0002. Andrey, are you still
> > working on this or others can pick it up?
> >
> > The patch is not on the commitfest, so I'm about to add it.
>
> Here is patch v5 where I accounted for the previous feedback from
> Masahiko Sawada and also made some other changes, see below.
>
> > How about the error message like "invalid input length for type uuid"?
> > I think "uuid" should be lower case as it indicates PostgreSQL uuid
> > data type, and it's better to use %s format instead of directly
> > writing "uuid" (see string_to_uuid() for example).
>
> Makes sense. Fixed.
>
> > As for the errdetail message, should we add "bytea" also after "got %d"?
>
> You probably meant "got %d bytes", not "got %d bytea". I believe the
> current message is fine, but maybe native speakers will correct us.
>
> > We already have tests for casting bytes to integer data types in
> > strings.sql. I suggest moving the casting tests from bytea to uuid
> > into therel.
>
> I disagree on the grounds that there are zero tests related to UUID in
> strings.sql; uuid.sql is a more appropriate place for these tests IMO.
> However if someone seconds the idea we can easily move the tests at
> any time.
>
> > For the uuid.sql file, we could add a test to verify that
> > a UUID value remains unchanged when it's cast to bytea and back to
> > UUID. For example,
> >
> > SELECT v = v::bytea::uuid as matched FROM gen_random_uuid() v;
>
> Good point. Added.
>
> > base32hex_encode() doesn't seem to add '=' paddings, but is it
> > intentional? I don't see any description in RFC 4648 that we can omit
> > '=' paddings.
>
> You are right, both base32 and base32hex should add paddings;
> substring() can be used if necessary. Fixed.
>
> > I think the patch should add tests not only for uuid data type but
> > also for general cases like other encodings.
>
> Yes, and the good place for these tests would be closer to other tests
> for encode() and decode() i.e. strings.sql. Fixed.
>
> While working on it I noticed some inconsistencies between base32hex
> implementation and our current implementation of base64. As an
> example, we don't allow `=` input:
>
> ```
> =# SELECT decode('=', 'base64');
> ERROR:  unexpected "=" while decoding base64 sequence
> ```
>
> ... while base32hex did. I fixed such inconsistencies too.
>
> > In uuid.sql tests, how about adding some tests to check if base32hex
> > maintains the sortability of UUIDv7 data?
>
> Agree. Added.
>
> > I think we should update the documentation in the uuid section about
> > casting data between bytea and uuid. For references, we have a similar
> > description for bytea and integer[1].
>
> Fair point. Fixed.
>

Thank you for updating the patch!

I've reviewed both patches and have some comments.

* 0001 patch

+       ereport(ERROR,
+               (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+                errmsg("invalid input length for type %s", "uuid"),
+                errdetail("Expected %d bytes, got %d.", UUID_LEN, len)));

I think we need to handle plural and singular forms depending on the
value. Or we can change it to "Expected size %d, got %d".

* 0002 patch:

                errhint("Valid encodings are \"%s\", \"%s\", \"%s\",
and \"%s\".",
                        "base64", "base64url", "escape", "hex")));

We need to add 'base32hex' here.

---
+                   ereport(ERROR,
+                           (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                            errmsg("unexpected \"=\" while decoding
%s sequence",
+                                   "base32hex")));

I think we can directly write 'base32hex' in the error message.

---
+   /* Verify no extra bits remain (padding bits should be zero) */
+   if (bits_in_buffer > 0 && (bits_buffer & ((1ULL << bits_in_buffer)
- 1)) != 0)
+       ereport(ERROR,
+               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                errmsg("invalid base32hex end sequence"),
+                errhint("Input data has non-zero padding bits.")));

This code checks if the remaining bits of the input data are all zero.
IIUC we don't have a similar check for base64 and base64url. For
instance, the following input data is accepted:

=# select decode('AB', 'base64');
 decode
--------
 \x00
(1 row)

I think it's better to have consistent behavior across our encoding.

I've attached a patch for the 0002 patch part that fixes the above
points (except for the last point) and has some minor fixes as well.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Вложения:
Hi,

> I've attached a patch for the 0002 patch part that fixes the above
> points (except for the last point) and has some minor fixes as well.

Applied, thanks.

> +   /* Verify no extra bits remain (padding bits should be zero) */
> +   if (bits_in_buffer > 0 && (bits_buffer & ((1ULL << bits_in_buffer)
> - 1)) != 0)
> +       ereport(ERROR,
> +               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> +                errmsg("invalid base32hex end sequence"),
> +                errhint("Input data has non-zero padding bits.")));
>
> This code checks if the remaining bits of the input data are all zero.
> IIUC we don't have a similar check for base64 and base64url. For
> instance, the following input data is accepted:
>
> =# select decode('AB', 'base64');
>  decode
> --------
>  \x00
> (1 row)
>
> I think it's better to have consistent behavior across our encoding.

Agree. Fixed.

-- 
Best regards,
Aleksander Alekseev

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Wed, Mar 18, 2026 at 4:14 AM Aleksander Alekseev
 wrote:
>
> Hi,
>
> > I've attached a patch for the 0002 patch part that fixes the above
> > points (except for the last point) and has some minor fixes as well.
>
> Applied, thanks.
>
> > +   /* Verify no extra bits remain (padding bits should be zero) */
> > +   if (bits_in_buffer > 0 && (bits_buffer & ((1ULL << bits_in_buffer)
> > - 1)) != 0)
> > +       ereport(ERROR,
> > +               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> > +                errmsg("invalid base32hex end sequence"),
> > +                errhint("Input data has non-zero padding bits.")));
> >
> > This code checks if the remaining bits of the input data are all zero.
> > IIUC we don't have a similar check for base64 and base64url. For
> > instance, the following input data is accepted:
> >
> > =# select decode('AB', 'base64');
> >  decode
> > --------
> >  \x00
> > (1 row)
> >
> > I think it's better to have consistent behavior across our encoding.
>
> Agree. Fixed.

Thank you for updating the patches!

I've made some minor changes to both patches (e.g., rewording the
documentation changes and commit messages etc), and attached the
updated patches.

I'm going to push these patches unless there is no further comment.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Hi,

> I've made some minor changes to both patches (e.g., rewording the
> documentation changes and commit messages etc), and attached the
> updated patches.
>
> I'm going to push these patches unless there is no further comment.

Many thanks! One little nitpick.

In 0001:

"""
The cast maps the 16-byte internal representation of a UUID directly
to a bytea datum. This is more efficient than going through a text
forepresentation.
"""

I'm pretty confident there is no such word "forepresentation".


-- 
Best regards,
Aleksander Alekseev


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Chengxi Sun <chengxisun92@gmail.com>
Дата:
I have a concern with base32hex_decode(). It only checks where the first = appears, 
but it does not validate the final group length or the required amount of padding. 
Because of that, some invalid inputs are accepted silently.

For example:

postgres=# SET bytea_output = hex;
SET
postgres=# SELECT '0' AS input, decode('0', 'base32hex');
 input | decode
-------+--------
 0     | \x
(1 row)

postgres=# SELECT '000' AS input , decode('000', 'base32hex');
 input | decode
-------+--------
 000   | \x00
(1 row)

postgres=# SELECT '24=' as input , decode('24=', 'base32hex');
 input | decode
-------+--------
 24=   | \x11
(1 row)

These looks good, but if we verify that with python:
% python3 - <<'PY'
import base64

tests = [
    "24",
    "24======",
    "0",
    "000",
    "24=",
]

for s in tests:
    try:
        out = base64.b32hexdecode(s, casefold=True)
        print(f"{s!r} -> OK {out.hex()}")
    except Exception as e:
        print(f"{s!r} -> ERROR: {e}")
PY

The outputs are:
'24' -> ERROR: Incorrect padding
'24======' -> OK 11
'0' -> ERROR: Incorrect padding
'000' -> ERROR: Incorrect padding
'24=' -> ERROR: Incorrect padding

I might be missing some context here, so I wanted to ask: is this behavior intentional, 
or would it make sense to enforce stricter validation for Base32hex input?  

Best regards,

Chengxi Sun

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Hi,

> I might be missing some context here, so I wanted to ask: is this behavior intentional,
> or would it make sense to enforce stricter validation for Base32hex input?

That's intentional - see the discussion above:

"""
[...]
This code checks if the remaining bits of the input data are all zero.
IIUC we don't have a similar check for base64 and base64url. For
instance, the following input data is accepted:

=# select decode('AB', 'base64');
 decode
--------
 \x00
(1 row)
"""

Also see the documentation in respect of padding.

-- 
Best regards,
Aleksander Alekseev


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Chengxi Sun <chengxisun92@gmail.com>
Дата:

This code checks if the remaining bits of the input data are all zero.
IIUC we don't have a similar check for base64 and base64url. For
instance, the following input data is accepted:

=# select decode('AB', 'base64');
 decode
--------
 \x00
(1 row)
"""

Thanks for the clarification, that makes sense. 

Best regards,

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Дата:
Masahiko Sawada  writes:

> I've made some minor changes to both patches (e.g., rewording the
> documentation changes and commit messages etc), and attached the
> updated patches.
>
> I'm going to push these patches unless there is no further comment.

Just one minor nitpick on my patch, which is that it should use
palloc_object(), which I wasn't aware of when I wrote it originally.

> diff --git a/src/backend/utils/adt/bytea.c b/src/backend/utils/adt/bytea.c
> index fd7662d41ee..4dc83671aa5 100644
> --- a/src/backend/utils/adt/bytea.c
> +++ b/src/backend/utils/adt/bytea.c
[...]
> +	if (len != UUID_LEN)
> +		ereport(ERROR,
> +				(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
> +				 errmsg("invalid input length for type %s", "uuid"),
> +				 errdetail("Expected %d bytes, got %d.", UUID_LEN, len)));
> +
> +	uuid = (pg_uuid_t *) palloc(sizeof(pg_uuid_t));

this should be:

+	uuid = palloc_object(pg_uuid_t);

> +	memcpy(uuid->data, VARDATA_ANY(v), UUID_LEN);
> +	PG_RETURN_UUID_P(uuid);
> +}
> +


- ilmari


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Thu, Mar 19, 2026 at 5:19 AM Aleksander Alekseev
 wrote:
>
> Hi,
>
> > I might be missing some context here, so I wanted to ask: is this behavior intentional,
> > or would it make sense to enforce stricter validation for Base32hex input?
>
> That's intentional - see the discussion above:
>
> """
> [...]
> This code checks if the remaining bits of the input data are all zero.
> IIUC we don't have a similar check for base64 and base64url. For
> instance, the following input data is accepted:
>
> =# select decode('AB', 'base64');
>  decode
> --------
>  \x00
> (1 row)
> """

Right. I've also tested base32hex encoding/decoding with other
libraries such as python's one. IIUC our base32hex implementation
doesn't necessarily work exactly the same as other libraries to have a
better consistency with the existing encodings such as base64 but I
believe that it doesn't contradict the RFC.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Thu, Mar 19, 2026 at 7:36 AM Dagfinn Ilmari Mannsåker
 wrote:
>
> Masahiko Sawada  writes:
>
> > I've made some minor changes to both patches (e.g., rewording the
> > documentation changes and commit messages etc), and attached the
> > updated patches.
> >
> > I'm going to push these patches unless there is no further comment.
>
> Just one minor nitpick on my patch, which is that it should use
> palloc_object(), which I wasn't aware of when I wrote it originally.
>
> > diff --git a/src/backend/utils/adt/bytea.c b/src/backend/utils/adt/bytea.c
> > index fd7662d41ee..4dc83671aa5 100644
> > --- a/src/backend/utils/adt/bytea.c
> > +++ b/src/backend/utils/adt/bytea.c
> [...]
> > +     if (len != UUID_LEN)
> > +             ereport(ERROR,
> > +                             (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
> > +                              errmsg("invalid input length for type %s", "uuid"),
> > +                              errdetail("Expected %d bytes, got %d.", UUID_LEN, len)));
> > +
> > +     uuid = (pg_uuid_t *) palloc(sizeof(pg_uuid_t));
>
> this should be:
>
> +       uuid = palloc_object(pg_uuid_t);
>
> > +     memcpy(uuid->data, VARDATA_ANY(v), UUID_LEN);
> > +     PG_RETURN_UUID_P(uuid);
> > +}
> > +

Good catch. I've pushed the 0001 patch after incorporating this change.

For 0002 patch, I don't push it yet as I've found a bug in the
decoding code during the self-review:

+           ereport(ERROR,
+                   (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                    errmsg("invalid symbol \"%.*s\" found while
decoding base32hex sequence",
+                           pg_mblen((const char *) &c), (const char *) &c)));

We should not use pg_mblen() anymore (c.f., CVE-2026-2006). And since
'c' is just a single byte on the stack, it leads to a buffer over-read
if the invalid character is a multi-byte character.

Also, a small nitpick is that we can use uint32 instead of uint64 for
'bits_buffer'. I've attached the updated patch as well as the
difference from the previous version.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Chengxi Sun <chengxisun92@gmail.com>
Дата:

I've run regression tests, LGTM overall.

Patch v8-0001 had some formatting issues, but they are already addressed in the fix-issue patch.

Best regards,

Chengxi Sun

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Вложения:
Hi,

> Also, a small nitpick is that we can use uint32 instead of uint64 for
> 'bits_buffer'. I've attached the updated patch as well as the
> difference from the previous version.

Then I suggest using uint32 for the bits_buffer variable in
base32hex_encode() too. Also we should use 1U instead of 1ULL with
uint32.

-- 
Best regards,
Aleksander Alekseev

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Вложения:
Hi,

> > Also, a small nitpick is that we can use uint32 instead of uint64 for
> > 'bits_buffer'. I've attached the updated patch as well as the
> > difference from the previous version.
>
> Then I suggest using uint32 for the bits_buffer variable in
> base32hex_encode() too. Also we should use 1U instead of 1ULL with
> uint32.

CI is not happy with the new test:

```
 SELECT decode('あ', 'base32hex'); -- error
-ERROR:  invalid symbol "あ" found while decoding base32hex sequence
+ERROR:  invalid symbol "ã" found while decoding base32hex sequence
```

Although it passes locally. My best guess is that something is off
with the database encoding on CI and that we shouldn't use this test.
We have a similar test which uses ASCII symbols only.

-- 
Best regards,
Aleksander Alekseev

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Fri, Mar 20, 2026 at 7:24 AM Aleksander Alekseev
 wrote:
>
> Hi,
>
> > > Also, a small nitpick is that we can use uint32 instead of uint64 for
> > > 'bits_buffer'. I've attached the updated patch as well as the
> > > difference from the previous version.
> >
> > Then I suggest using uint32 for the bits_buffer variable in
> > base32hex_encode() too. Also we should use 1U instead of 1ULL with
> > uint32.
>
> CI is not happy with the new test:
>
> ```
>  SELECT decode('あ', 'base32hex'); -- error
> -ERROR:  invalid symbol "あ" found while decoding base32hex sequence
> +ERROR:  invalid symbol "ã" found while decoding base32hex sequence
> ```
>
> Although it passes locally. My best guess is that something is off
> with the database encoding on CI and that we shouldn't use this test.
> We have a similar test which uses ASCII symbols only.

Good catch. Yes, we should not use this test depending on the database
encoding and it seems we can omit this test in the first place.

The patch looks basically good to me. I've made some changes to the
regression test part as I want to have round-trip tests. I've merged
the tests checking the sortability to the existing tests and added
round-trip tests. With this change, we can test round-trip tests and
sortability tests with random UUID value in every test run while
minimizing the test time. Feedback is very welcome.


Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Mar 24, 2026, at 09:17, Masahiko Sawada  wrote:
> 
> On Fri, Mar 20, 2026 at 7:24 AM Aleksander Alekseev
>  wrote:
>> 
>> Hi,
>> 
>>>> Also, a small nitpick is that we can use uint32 instead of uint64 for
>>>> 'bits_buffer'. I've attached the updated patch as well as the
>>>> difference from the previous version.
>>> 
>>> Then I suggest using uint32 for the bits_buffer variable in
>>> base32hex_encode() too. Also we should use 1U instead of 1ULL with
>>> uint32.
>> 
>> CI is not happy with the new test:
>> 
>> ```
>> SELECT decode('あ', 'base32hex'); -- error
>> -ERROR:  invalid symbol "あ" found while decoding base32hex sequence
>> +ERROR:  invalid symbol "ã" found while decoding base32hex sequence
>> ```
>> 
>> Although it passes locally. My best guess is that something is off
>> with the database encoding on CI and that we shouldn't use this test.
>> We have a similar test which uses ASCII symbols only.
> 
> Good catch. Yes, we should not use this test depending on the database
> encoding and it seems we can omit this test in the first place.
> 
> The patch looks basically good to me. I've made some changes to the
> regression test part as I want to have round-trip tests. I've merged
> the tests checking the sortability to the existing tests and added
> round-trip tests. With this change, we can test round-trip tests and
> sortability tests with random UUID value in every test run while
> minimizing the test time. Feedback is very welcome.
> 
> 
> Regards,
> 
> --
> Masahiko Sawada
> Amazon Web Services: https://aws.amazon.com
> 

V11 overall looks good to me. A couple of comments wrt the tests.

1
```
+		else
+			ereport(ERROR,
+					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+					 errmsg("invalid symbol \"%.*s\" found while decoding base32hex sequence",
+							pg_mblen_range(s - 1, srcend), s - 1)));
```

I noticed the use of pg_mblen_range(). Since base32hex itself is single-ASCII only, my first thought was that we might not need a multibyte-aware function here. But then I realized that a multibyte string could still be passed to decode(), and pg_mblen_range() helps report the invalid multibyte character correctly in the error message.

I tested it like this:
```
evantest=# SELECT decode('你哈', 'base32hex');
ERROR:  invalid symbol "你" found while decoding base32hex sequence
```

The error message looks good to me. So maybe it would be worth adding a test case for decode() with multibyte characters.

2
```
+       accepts both padded and unpadded input. Decoding is case-insensitive and ignores
+       whitespace characters.
```

The doc says whitespace characters are silently ignored, so I tested this:
```
evantest=# SELECT decode('a a==', 'base32hex');
 decode
--------
 \x52
(1 row)

evantest=# SELECT decode(' a a==', 'base32hex');
 decode
--------
 \x52
(1 row)

evantest=# SELECT decode(' a a== ', 'base32hex');
 decode
--------
 \x52
(1 row)
```

It looks like leading, trailing, and embedded whitespace are all ignored. But I don’t see a test case covering this behavior, so maybe it would be good to add one.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Hi,

> > The patch looks basically good to me. I've made some changes to the
> > regression test part as I want to have round-trip tests. I've merged
> > the tests checking the sortability to the existing tests and added
> > round-trip tests. With this change, we can test round-trip tests and
> > sortability tests with random UUID value in every test run while
> > minimizing the test time. Feedback is very welcome.

v11 looks good to me.

> It looks like leading, trailing, and embedded whitespace are all ignored. But I don’t see a test case covering this behavior, so maybe it would be good to add one.

I intentionally didn't include this test because the code is trivial:

``
        /* Skip whitespace */
        if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
            continue;
```

And also because we never tested it for base64. If we want to start
testing it we should add tests both for base64 and base32hex which IMO
should be a separate patch.

-- 
Best regards,
Aleksander Alekseev


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Tue, Mar 24, 2026 at 8:31 AM Aleksander Alekseev
 wrote:
>
> Hi,
>
> > > The patch looks basically good to me. I've made some changes to the
> > > regression test part as I want to have round-trip tests. I've merged
> > > the tests checking the sortability to the existing tests and added
> > > round-trip tests. With this change, we can test round-trip tests and
> > > sortability tests with random UUID value in every test run while
> > > minimizing the test time. Feedback is very welcome.
>
> v11 looks good to me.
>
> > It looks like leading, trailing, and embedded whitespace are all ignored. But I don’t see a test case covering this behavior, so maybe it would be good to add one.
>
> I intentionally didn't include this test because the code is trivial:
>
> ``
>         /* Skip whitespace */
>         if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
>             continue;
> ```
>
> And also because we never tested it for base64. If we want to start
> testing it we should add tests both for base64 and base32hex which IMO
> should be a separate patch.

Agreed.

I've attached the updated version patch that includes the following points:

- changed the order of encodings in the doc and the hint message to
maintain alphabetical order.
- changed the query example to extract data from the encoded UUID
value to use rtrim() as it's more intuitive.
- added some regression tests for decoding unpadded inputs.

I'm going to push the patch unless there are comments on these changes.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Masahiko Sawada  writes:
> I'm going to push the patch unless there are comments on these changes.

BF member hippopotamus has just demonstrated that this
"base32hex" representation is not in fact sort-stable at all [1]:

 SELECT array_agg(id ORDER BY guid_encoded) FROM guid3;
           array_agg           
 ------------------------------
- {1,2,3,4,5,6,7,8,9,10,11,12}
+ {12,1,2,3,4,5,7,6,8,9,10,11}
 (1 row)
 
I believe what's happening there is that in cs_CZ locale,
"V" doesn't follow simple ASCII sort ordering.  (I don't
know the exact rules in Czech, but certainly we've seen
that locale break a lot of other test queries.)

I wonder whether this discovery puts enough of a hole in the
value-proposition for base32hex that we should just revert
this patch altogether.  "It works except in some locales"
isn't a very appetizing prospect, so the whole idea is starting
to feel more like a foot-gun than a widely-useful feature.

			regards, tom lane

[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=hippopotamus&dt=2026-03-25%2022%3A38%3A14


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Tomas Vondra <tomas@vondra.me>
Дата:


On 3/26/26 00:40, Tom Lane wrote:
> Masahiko Sawada  writes:
>> I'm going to push the patch unless there are comments on these changes.
> 
> BF member hippopotamus has just demonstrated that this
> "base32hex" representation is not in fact sort-stable at all [1]:
> 
>  SELECT array_agg(id ORDER BY guid_encoded) FROM guid3;
>            array_agg           
>  ------------------------------
> - {1,2,3,4,5,6,7,8,9,10,11,12}
> + {12,1,2,3,4,5,7,6,8,9,10,11}
>  (1 row)
>  
> I believe what's happening there is that in cs_CZ locale,
> "V" doesn't follow simple ASCII sort ordering.  (I don't
> know the exact rules in Czech, but certainly we've seen
> that locale break a lot of other test queries.)
> 

With cs_CZ all letters sort *before* numbers, while in en_US it's the
other way around. V is not special in any way.

> I wonder whether this discovery puts enough of a hole in the
> value-proposition for base32hex that we should just revert
> this patch altogether.  "It works except in some locales"
> isn't a very appetizing prospect, so the whole idea is starting
> to feel more like a foot-gun than a widely-useful feature.
> 

Seems like that.


regards

-- 
Tomas Vondra



Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Tomas Vondra  writes:
> On 3/26/26 00:40, Tom Lane wrote:
>> I believe what's happening there is that in cs_CZ locale,
>> "V" doesn't follow simple ASCII sort ordering.

> With cs_CZ all letters sort *before* numbers, while in en_US it's the
> other way around. V is not special in any way.

Ah, sorry, I should have researched a bit instead of relying on
fading memory.  The quirk I was thinking of is that in cs_CZ,
"ch" sorts after "h":

u8=# select 'h' < 'ch'::text collate "en_US";
 ?column? 
----------
 f
(1 row)

u8=# select 'h' < 'ch'::text collate "cs_CZ";
 ?column? 
----------
 t
(1 row)

Regular hex encoding isn't bitten by that because it doesn't
use 'h' in the text form ... but this base32hex thingie does.

However, your point is also correct:

u8=# select '0' < 'C'::text ;
 ?column? 
----------
 t
(1 row)

u8=# select '0' < 'C'::text collate "cs_CZ";
 ?column? 
----------
 f
(1 row)

and that breaks "text ordering matches numeric ordering"
for both traditional hex and base32hex.  So maybe this
is not as big a deal as I first thought.  We need a fix
for the new test though.  Probably adding COLLATE "C"
would be enough.

			regards, tom lane


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Wed, Mar 25, 2026 at 5:35 PM Tom Lane  wrote:
>
> Tomas Vondra  writes:
> > On 3/26/26 00:40, Tom Lane wrote:
> >> I believe what's happening there is that in cs_CZ locale,
> >> "V" doesn't follow simple ASCII sort ordering.
>
> > With cs_CZ all letters sort *before* numbers, while in en_US it's the
> > other way around. V is not special in any way.
>
> Ah, sorry, I should have researched a bit instead of relying on
> fading memory.  The quirk I was thinking of is that in cs_CZ,
> "ch" sorts after "h":
>
> u8=# select 'h' < 'ch'::text collate "en_US";
>  ?column?
> ----------
>  f
> (1 row)
>
> u8=# select 'h' < 'ch'::text collate "cs_CZ";
>  ?column?
> ----------
>  t
> (1 row)
>
> Regular hex encoding isn't bitten by that because it doesn't
> use 'h' in the text form ... but this base32hex thingie does.
>
> However, your point is also correct:
>
> u8=# select '0' < 'C'::text ;
>  ?column?
> ----------
>  t
> (1 row)
>
> u8=# select '0' < 'C'::text collate "cs_CZ";
>  ?column?
> ----------
>  f
> (1 row)
>
> and that breaks "text ordering matches numeric ordering"
> for both traditional hex and base32hex.  So maybe this
> is not as big a deal as I first thought.  We need a fix
> for the new test though.  Probably adding COLLATE "C"
> would be enough.

Thank you for the report and the analysis.

I've reproduced the issue with "cs_CZ" collation and adding COLLATE
"C" to the query resolves it. It seems also a good idea to add a note
in the documentation too as users might face the same issue. For
example,

To maintain the lexicographical sort order of the encoded data, ensure
that the text is sorted using the C collation (e.g., using COLLATE
"C"). Natural language collations may sort characters differently and
break the ordering.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Wed, Mar 25, 2026 at 6:09 PM Masahiko Sawada  wrote:
>
> On Wed, Mar 25, 2026 at 5:35 PM Tom Lane  wrote:
> >
> > Tomas Vondra  writes:
> > > On 3/26/26 00:40, Tom Lane wrote:
> > >> I believe what's happening there is that in cs_CZ locale,
> > >> "V" doesn't follow simple ASCII sort ordering.
> >
> > > With cs_CZ all letters sort *before* numbers, while in en_US it's the
> > > other way around. V is not special in any way.
> >
> > Ah, sorry, I should have researched a bit instead of relying on
> > fading memory.  The quirk I was thinking of is that in cs_CZ,
> > "ch" sorts after "h":
> >
> > u8=# select 'h' < 'ch'::text collate "en_US";
> >  ?column?
> > ----------
> >  f
> > (1 row)
> >
> > u8=# select 'h' < 'ch'::text collate "cs_CZ";
> >  ?column?
> > ----------
> >  t
> > (1 row)
> >
> > Regular hex encoding isn't bitten by that because it doesn't
> > use 'h' in the text form ... but this base32hex thingie does.
> >
> > However, your point is also correct:
> >
> > u8=# select '0' < 'C'::text ;
> >  ?column?
> > ----------
> >  t
> > (1 row)
> >
> > u8=# select '0' < 'C'::text collate "cs_CZ";
> >  ?column?
> > ----------
> >  f
> > (1 row)
> >
> > and that breaks "text ordering matches numeric ordering"
> > for both traditional hex and base32hex.  So maybe this
> > is not as big a deal as I first thought.  We need a fix
> > for the new test though.  Probably adding COLLATE "C"
> > would be enough.
>
> Thank you for the report and the analysis.
>
> I've reproduced the issue with "cs_CZ" collation and adding COLLATE
> "C" to the query resolves it. It seems also a good idea to add a note
> in the documentation too as users might face the same issue. For
> example,
>
> To maintain the lexicographical sort order of the encoded data, ensure
> that the text is sorted using the C collation (e.g., using COLLATE
> "C"). Natural language collations may sort characters differently and
> break the ordering.
>

Attached the patch doing the above idea.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Wed, Mar 25, 2026 at 6:21 PM Masahiko Sawada  wrote:
>
> On Wed, Mar 25, 2026 at 6:09 PM Masahiko Sawada  wrote:
> >
> > On Wed, Mar 25, 2026 at 5:35 PM Tom Lane  wrote:
> > >
> > > Tomas Vondra  writes:
> > > > On 3/26/26 00:40, Tom Lane wrote:
> > > >> I believe what's happening there is that in cs_CZ locale,
> > > >> "V" doesn't follow simple ASCII sort ordering.
> > >
> > > > With cs_CZ all letters sort *before* numbers, while in en_US it's the
> > > > other way around. V is not special in any way.
> > >
> > > Ah, sorry, I should have researched a bit instead of relying on
> > > fading memory.  The quirk I was thinking of is that in cs_CZ,
> > > "ch" sorts after "h":
> > >
> > > u8=# select 'h' < 'ch'::text collate "en_US";
> > >  ?column?
> > > ----------
> > >  f
> > > (1 row)
> > >
> > > u8=# select 'h' < 'ch'::text collate "cs_CZ";
> > >  ?column?
> > > ----------
> > >  t
> > > (1 row)
> > >
> > > Regular hex encoding isn't bitten by that because it doesn't
> > > use 'h' in the text form ... but this base32hex thingie does.
> > >
> > > However, your point is also correct:
> > >
> > > u8=# select '0' < 'C'::text ;
> > >  ?column?
> > > ----------
> > >  t
> > > (1 row)
> > >
> > > u8=# select '0' < 'C'::text collate "cs_CZ";
> > >  ?column?
> > > ----------
> > >  f
> > > (1 row)
> > >
> > > and that breaks "text ordering matches numeric ordering"
> > > for both traditional hex and base32hex.  So maybe this
> > > is not as big a deal as I first thought.  We need a fix
> > > for the new test though.  Probably adding COLLATE "C"
> > > would be enough.
> >
> > Thank you for the report and the analysis.
> >
> > I've reproduced the issue with "cs_CZ" collation and adding COLLATE
> > "C" to the query resolves it. It seems also a good idea to add a note
> > in the documentation too as users might face the same issue. For
> > example,
> >
> > To maintain the lexicographical sort order of the encoded data, ensure
> > that the text is sorted using the C collation (e.g., using COLLATE
> > "C"). Natural language collations may sort characters differently and
> > break the ordering.
> >
>
> Attached the patch doing the above idea.

Pushed the fix without the documentation changes to make the buildfarm
animals happy first.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com


Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:


> On 26 Mar 2026, at 04:40, Tom Lane  wrote:
> 
> I wonder whether this discovery puts enough of a hole in the
> value-proposition for base32hex that we should just revert
> this patch altogether.  "It works except in some locales"
> isn't a very appetizing prospect, so the whole idea is starting
> to feel more like a foot-gun than a widely-useful feature.

To be precise, this discovery cast shadows on argument "[base32hex is ]lexicographically sortable format that preserves temporal ordering for UUIDv7". And, actually, any UUID. But I do not think it invalidates the argument completely.

It's taken from RFC[0], actually, that states:
 One property with this alphabet, which the base64 and base32
 alphabets lack, is that encoded data maintains its sort order when
 the encoded data is compared bit-wise.


RFC does not give any other benefits.
Personally, I like that it's compact, visually better than base64, and RFC-compliant.
And IMO argument "base32hex is lexicographically sortable format that preserves ordering for UUID in C locale" is still very strong.
Though, there's a little footy shooty in last 3 words.


Best regards, Andrey Borodin.


[0] https://datatracker.ietf.org/doc/html/rfc4648#page-10

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:


> On 26 Mar 2026, at 04:40, Tom Lane  wrote:
> 
> I wonder whether this discovery puts enough of a hole in the
> value-proposition for base32hex that we should just revert
> this patch altogether.  

After thinking more about it, I do not see grounds for reverting.

> "It works except in some locales"

It works per RFC. It adds value. It's documented precisely.

Sortability in cs_CZ only stands in a way for this format to become "the one UUID format to rule them all" instead of canonical in the future.
We should let IETF WG know that digits and letters are not always ordered as they expect. Hopefully Sergey will handle this.

BTW, thanks to Alexander and Masahiko for pushing this to finish line! I'm listed as author, but they done 99.9% of work on making this functionality.


Best regards, Andrey Borodin.

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Thu, Mar 26, 2026 at 1:32 AM Andrey Borodin  wrote:
>
>
>
> > On 26 Mar 2026, at 04:40, Tom Lane  wrote:
> >
> > I wonder whether this discovery puts enough of a hole in the
> > value-proposition for base32hex that we should just revert
> > this patch altogether.  "It works except in some locales"
> > isn't a very appetizing prospect, so the whole idea is starting
> > to feel more like a foot-gun than a widely-useful feature.
>
> To be precise, this discovery cast shadows on argument "[base32hex is ]lexicographically sortable format that preserves temporal ordering for UUIDv7". And, actually, any UUID. But I do not think it invalidates the argument completely.
>
> It's taken from RFC[0], actually, that states:
>  One property with this alphabet, which the base64 and base32
>  alphabets lack, is that encoded data maintains its sort order when
>  the encoded data is compared bit-wise.
>
>
> RFC does not give any other benefits.
> Personally, I like that it's compact, visually better than base64, and RFC-compliant.
> And IMO argument "base32hex is lexicographically sortable format that preserves ordering for UUID in C locale" is still very strong.
> Though, there's a little footy shooty in last 3 words.

Yeah, I still find that base32hex is useful.

As I mentioned in another email, I think we should make a note the
fact that "base32hex is lexicographically sortable format that
preserves ordering for UUID in C locale" in the documentation. I've
attached the patch. Feedback is very welcome.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
Вложения:


> On 26 Mar 2026, at 22:30, Masahiko Sawada  wrote:
> 
>  Feedback is very welcome.

The patch is fine from my POV.

Please consider these small improvements to the patch. Basically, we reference to formula stated by RFC where possible.
0001 is intact.


Best regards, Andrey Borodin.

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
Вложения:
On Thu, Mar 26, 2026 at 10:59 AM Andrey Borodin  wrote:
>
>
>
> > On 26 Mar 2026, at 22:30, Masahiko Sawada  wrote:
> >
> >  Feedback is very welcome.
>
> The patch is fine from my POV.
>
> Please consider these small improvements to the patch. Basically, we reference to formula stated by RFC where possible.
> 0001 is intact.

Thank you for the suggestion. It looks good to me.

I've merged these patches and am going to push barring any objections.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions

От:
Masahiko Sawada <sawada.mshk@gmail.com>
Дата:
On Thu, Mar 26, 2026 at 3:01 PM Masahiko Sawada  wrote:
>
> On Thu, Mar 26, 2026 at 10:59 AM Andrey Borodin  wrote:
> >
> >
> >
> > > On 26 Mar 2026, at 22:30, Masahiko Sawada  wrote:
> > >
> > >  Feedback is very welcome.
> >
> > The patch is fine from my POV.
> >
> > Please consider these small improvements to the patch. Basically, we reference to formula stated by RFC where possible.
> > 0001 is intact.
>
> Thank you for the suggestion. It looks good to me.
>
> I've merged these patches and am going to push barring any objections.
>

Pushed.

As for the original base32hex encoding commit, I'd like to leave a
note that I've changed the patch to use the lookup table for decoding
before the push as it's more efficient.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com


FAQ