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 1vEY3T-00D8UR-MH for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Oct 2025 19:11:27 +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 1vEY3R-00A6je-OF for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Oct 2025 19:11:24 +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 1vEY3R-00A6jV-EE for pgsql-hackers@lists.postgresql.org; Thu, 30 Oct 2025 19:11:24 +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 1vEY3N-0057OZ-2O for pgsql-hackers@postgresql.org; Thu, 30 Oct 2025 19:11:23 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-5930f751531so1505874e87.3 for ; Thu, 30 Oct 2025 12:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761851479; x=1762456279; 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=vMNBkAWH46bFQ/MF/Pz1TIO4W6U/61guKYA9FIs6Jtg=; b=JRRrnNHqA0YXolm2D1Ljl2UvjLe8H8Z/agC/7YZs9lSTUkZGBdjnZbLmwrREcG8bMA UwwrNeRLCYU/CftJe4kxNXvtVjnNJhqx4HapaPxUOv6DIdchjNGC+5ZmmBqIwGsJg/fi LAXLYOuH3xpPKKybLoVW4LnU+bGpX7lwhDy4+Ywg3gBxlgH8xX2avDtu2//X98j4OUgt d1zfWjWdw6wKDlz3+8Tt/MtUX9jyAtQx5toeKe/T773UImVWDBwfZabDottGzBJoEUu5 XmPCOa8g/zf8GK82jsf+5QhTdtkdct35d/CovmZnZ924mMvbGNiCNn5uVrYk4DHDzsOI EK8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761851479; x=1762456279; 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=vMNBkAWH46bFQ/MF/Pz1TIO4W6U/61guKYA9FIs6Jtg=; b=ZRNfSvWKuau7qQlplPbaJvbOZzzvR46RxJ1NlArYzEn7rp8fBGjq6XFAY32DW487my swxiFxCnX/z6PFrClSjYlOrwnBOzU/1Im87lkvsUTG3Zu5KOGKyYKCPrGpDz1SaQipUV ZF+UlDVYDHQmnSLIsock9UzOUjT61pn0PKAx9kQ7awdBhfy7V9LOgvPTGozWE0ovXDAC l60xPTrvyNJbITdBojSuCIzKMUHbkvczXirUWla3GccicJj0yymR9tm3Uwd4A44xh/At M4TrZzBJTSiQ+Gb9Q9pZSz83lgdOx42a0PvvF56wNB2TvHbIbpnTOZiiJLVNzmpA+E7C qEZA== X-Forwarded-Encrypted: i=1; AJvYcCVJn1Q1iw2T0xqUeWhvRNdWZvB5lp6L6FUcqwYQuQctqdUrhUQClfr7SoNhHZQe0L8EkuMckAjc31QXFTh1@postgresql.org X-Gm-Message-State: AOJu0Yx1MmUwUMZknY7CHWt9bkhvlIbZNIlWa48sdNvQ3PGXNQYbuY2d F8dS5pe4/5zlwdPepUH/JTDPWuvBm886gN323jCkW+lt3twUg0FW6LIuaNYHjJDmGKrnfK1MYUz Jnxn/KQJcfnA7/RsxxZzJX+q1rmt52qQ= X-Gm-Gg: ASbGncuyow574LW9bOzF98TJzFALOzl8n5O9I6raKG2Ao4xDmYyHECA7hQCDnx6uoYu qUZ+9J/NSzaX5B5RviDDYs21BkJvbufntREGbJUkbTu8zQ2mKI/hb+VdqkLFopeUowZRDKj9hT6 5zPh9EJql5lNgQWrBYwixHdVAtWvDu7Texymgj2FLMYGUtIXaII0ycxZJgOv6DrKTBp85917DJ5 jPwLO5R9mrYZCbb253kqZLi1L+OmYC5juhN58c6wUrJ/c0enJD1QJs97Kd9ErrZDXwQl9Dd X-Google-Smtp-Source: AGHT+IG+uNEkCQwVq12cnY6Wv0zGWVvcB7X0swC8liZX2oLuJvKLjEjODZQtr7qH68vjDiQ0WSWReVJ4s84UY7cElY8= X-Received: by 2002:ac2:4c4f:0:b0:57e:c1e6:ba8 with SMTP id 2adb3069b0e04-5941d50dcbcmr296484e87.12.1761851478602; Thu, 30 Oct 2025 12:11:18 -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> <574624399.175025.1761290201491@mail.yahoo.com> <953203149.383019.1761345585325@mail.yahoo.com> <6F76FA61-E2DC-44EF-9504-889D9BDB4EBD@yandex-team.ru> <1154454839.957923.1761604611424@mail.yahoo.com> <87ldkv8cog.fsf@wibble.ilmari.org> <87ikfz7zcu.fsf@wibble.ilmari.org> <9CB824CC-70DC-4165-AC6A-9664F47209EE@yandex-team.ru> In-Reply-To: <9CB824CC-70DC-4165-AC6A-9664F47209EE@yandex-team.ru> From: Masahiko Sawada Date: Thu, 30 Oct 2025 12:10:42 -0700 X-Gm-Features: AWmQ_bnVUhWh_5FCemXpp0M7xfeqXv7HCN0oHOUkIrq638cpDuDYLAY_VGSR8zo Message-ID: Subject: Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions To: Andrey Borodin Cc: =?UTF-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= , Jelte Fennema-Nio , Sergey Prokhorenko , 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 Wed, Oct 29, 2025 at 5:19=E2=80=AFAM 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 pat= ch 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_REPRESENTATI= ON), - errmsg("invalid uuid length")); + (errcode(ERRCODE_INVALID_BINARY_REPRESENTAT= ION), + 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 =3D 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 '=3D' paddings, but is it intentional? I don't see any description in RFC 4648 that we can omit '=3D' 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 --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com