Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vC2RD-008EQy-Ad for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Oct 2025 21:01:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vC2RB-00BosL-L9 for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Oct 2025 21:01:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vC2RB-00BosD-B4 for pgsql-hackers@lists.postgresql.org; Thu, 23 Oct 2025 21:01:32 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vC2R7-003sD0-30 for pgsql-hackers@postgresql.org; Thu, 23 Oct 2025 21:01:32 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-592f29e273bso1211061e87.0 for ; Thu, 23 Oct 2025 14:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761253288; x=1761858088; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FjgBui0tMOaOLulL/uyhzwEOxfjeMnROVM+y8q5C2G0=; b=WvDA7HqT6zEIItfZBYnXo4CYjqJC70xdNXHdDjbILkGjxyNN1Vnh/aeMOE2EGqIZ3w 0899xn2h60oBNAGCtt93OVHA2KX+bwFu84vo3caqT+HWHiSvZWt+YY3Rr+gZUN0OghWT 0byGRymGp9vsXMAOHXLXwOO79iKN8su8wF9Mbq6P5+wh5k5PP9+Y/6t7TrJeQWJtyF8w XMTfxj/FCc63q2oF+haU6eXv5VmdaUdJGpleRGBJH/G3FU02txP8LE+tcoDZwnV8kj0V LVORT3uYI2DruLE2pQ4vbegfoMm5oLbukJMHIlaatRpYok/6AYpAllCYRnUT4Bq8G1gg njHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761253288; x=1761858088; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FjgBui0tMOaOLulL/uyhzwEOxfjeMnROVM+y8q5C2G0=; b=PHNdyyzwXNHXvSCSXEiHi6Urs6lkHFbTU3tkI3wqeuNxL66mOkJMETNzoF51NcCzZ4 vM48xCCr9yXXAYm8VXvhwkv5EDYAdLuu4pz/17fRjVMaiZppQ4yxOaDuxUch3bkcO3wi s4CxGj1qMRsKFyAL+wbtuzQq2pOUX+HxmZfSJdwLC7leE5d6wezEhMVNDkk63BTdBRVU wFz3Xt0eXv3VKVPxTpUU2im+YM2Xd0ZYhyF62Puk/vsHeDFcWGBt9ARmaYsjOaPcr+rv IODMV4xvbnJ5uONNs8lxnpXvFviCenrrPi3tmxkz63/dMo7UBPUgGvaIHDa4tKDdW63/ lFIw== X-Forwarded-Encrypted: i=1; AJvYcCW2V33QJDB7OFGvx8tzhUdnOI5aeh+aB2oRd2w9iYP+ANzTzGnQc08EiqaEetQJ+lgpjFR20ZBnvtu6vL3p@postgresql.org X-Gm-Message-State: AOJu0YwY+ZVwm0zYkSIGvtY9+o2+F63V2xf4BcoaOORIYCzwr9vwHzoX /eNXLuUiNgJZMiZqtd7xkSbaNYB3ZmT3SsT595p629eGnNqDt+ZVqKofIEh8a+AHV/FprshAXfy evbQph+I1O9aurXW3BVGXh4JwYPJzUII= X-Gm-Gg: ASbGncticq03bn42YfzTLno9zawV2PONRlEgrfvfa4ELUTI0K76P94Rmzc14cBWyO0b UCvyJbtpFKvlDlIL8GKR+o9EBjoMgGVgk0tXkTcP0u+ew1NQRY0/+YoEiOBl4lvq25X30Da+vPX J5ESMsBROXoR5Ohg5dsDHmRbmLnUg9E8S4qvIZqGG1n1v+u/0OnwbpjlTyN68qn2rgxLpm9beJ8 X0u/PfqrQPLTfpitLNChbHQV9sdRhbOiFxXxr4GQeGZyF1nYUo6zgRmaibAnYZR3iuFaSje X-Google-Smtp-Source: AGHT+IFZn88ywB2QZQKXkBD9wtDjNAMU/FsZfw7vqiBaBPktwh/SsyBE3JwzeCqQMpH3Lk0MAhgdvWm5tlG8QE7WQNo= X-Received: by 2002:a05:6512:b27:b0:57c:2474:371f with SMTP id 2adb3069b0e04-592f5a62b9amr1379864e87.45.1761253288122; Thu, 23 Oct 2025 14:01:28 -0700 (PDT) MIME-Version: 1.0 References: <1791665551.452444.1761209220211.ref@mail.yahoo.com> <1791665551.452444.1761209220211@mail.yahoo.com> <18022523-0F8F-4C07-AFF5-57DC9086D78E@yandex-team.ru> <1895971769.8343.1761240853939@mail.yahoo.com> In-Reply-To: <1895971769.8343.1761240853939@mail.yahoo.com> From: Masahiko Sawada Date: Thu, 23 Oct 2025 14:00:50 -0700 X-Gm-Features: AWmQ_bnqbDMTRl-CwjGvWLrZvXC04i6FkTyfD_FBwwl1iYrUsiyG49JujQBB-9M Message-ID: Subject: Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions To: Sergey Prokhorenko Cc: Andrey Borodin , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Oct 23, 2025 at 10:34=E2=80=AFAM Sergey Prokhorenko wrote: > > >> The value of converting uuid to base32 is not obvious though, so I > >> would recommend explaining it in more detail. > > > Yes, and maybe some examples of other systems that adopted this format = would be handy too. > > DNSSEC (https://en.wikipedia.org/wiki/Domain_Name_System_Security_Extensi= ons) > many encoders and decoders > > > Sergey, can you, please, extend reasoning why this particular format is= prominent? RFC 4648 describes a bunch of formats. > > > > Best regards, Andrey Borodin. > > > Base32hex: > 1. Preserves sort order (unlike base64) > 2. Compact > 3. Standardized and therefore implemented consistently everywhere > 4. Implemented in many programming languages' standard libraries > 5. Does not require specifying character case during dictation > 6. Has simple and high-performance encoding and decoding algorithms (nece= ssary for system integration using JSON) > > The only compact text encoding eliminates the problem of incompatibility.= The authors and contributors of RFC 9562 were categorically against having= multiple encodings for UUIDs. They wanted to have only one compact, sort-o= rder-preserving text encoding. For compatibility, they added the canonical = UUID format. Due to time constraints, the compact encoding was not included= in RFC 9562. > > In databases, UUIDs should preferably be stored in binary format (the UUI= D type in PostgreSQL) according to RFC 9562. > > Intermediate formats (bytea) reduce performance, which is the very reason= we even abandoned the more compact base36 encoding. Given that what uuid_to_base32hex() actually does is encoding the input UUID, I find that it could be confusing if we have a similar function other than encode() function. Also, we could end up introducing as many encoding and decoding functions dedicated for UUID as we want to support encoding methods, bloating the functions. So as the first step, +1 for supporting base32hex for encode() and decode() functions and supporting the UUID <-> bytea conversion. I believe it would cover most use cases and the cost of UUID <-> bytea conversion is negligible. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com