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.96) (envelope-from ) id 1w81sF-0008wM-2j for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 20:09:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w81rE-002BhF-1S for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 20:08:08 +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.96) (envelope-from ) id 1w81rE-002Bh6-01 for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 20:08:08 +0000 Received: from mail-dl1-x122b.google.com ([2607:f8b0:4864:20::122b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w81rA-000000004UY-2AmZ for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 20:08:07 +0000 Received: by mail-dl1-x122b.google.com with SMTP id a92af1059eb24-12a693cdf29so1340659c88.0 for ; Wed, 01 Apr 2026 13:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775074082; cv=none; d=google.com; s=arc-20240605; b=E2/MtM5wxhP55o9Kz23LOFNbwuIfd3rFbRd5zrElL54NuvQIvf9HzTydBXdN9VvLSM lACfQG3fLwvvkqamZIaLRhcOFpJV3ASz9czAHW334Q7fK8AvqgcZs4FZ0eM585bNKRqE sHGnm92haGwUjLrfEvWpmR6kAbX4hG7qKt5SYUvoma5Il3LwNwNvSAA1ifAS2wXL5xGP v8fwgmE+Nlm98egkRJ9UB/KsMTblnSQBJtzmkZAe0740//GveLBJYKJVZsQqa9/GFVUa uGNkxEkpkad22xcP5oe/LnJb4kUhtj7mLS+Zyv7KCvHx1FGGKNVaemo/+ILwrDqAfvwr lREw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=EmReYcYw9J6Amp1NheLT+ENxqbKCjHRzmz5M8om8UX8=; fh=GoXe8t1WHfFC+AeTqG5SlE7XNZRcYyOqwt/+cMjji4s=; b=bSe+pe0vpFBdkSaP62fKzAfaarE2Os600KxQAJIMnTezqnsokWRKjTHscoQktDMGz3 H2rJ5B/ntoEWnylMpiq5zmM2p+uvQzfPQ5dkChmQlk/xjDeq5nlUvU0QQa8yk2CjE+nN DxqRpFEp329sntK/RlTf2g8SwT9HDy4EtmfYlIuSqQBEaUQCkczrbNTIBCCYSv8JB7B7 TQEYukrLnX6TWLLue7BSnURuToPztxyYbFhXyIeiJ6b85OhHnmGLg/d9io4o/YaYyrw9 ZVEdUFiPxyQMwY3e0ZLsz5qJCWTFPdq/x1W3uElMroiwLveoyYM+Wrm7VBmMh2w8djnJ L7dw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775074082; x=1775678882; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=EmReYcYw9J6Amp1NheLT+ENxqbKCjHRzmz5M8om8UX8=; b=dJtakISMJMSy9hmlZaijAx1eLdDYYNdVvcWR3l0uwOuIXlNhdlG6wEeDMkbVyFPPK+ zktMydZo6swBO2npSThvYO50XuNasFFgxEvlpMozpaOnWpocIxptgpyaKbvmtX3SN9qQ 5Qjoqc20SlRB/0RZqBQ8jiwcZqXdTVnWgOaGIZ3ecMWTEK5FCSUBxVU6to6gmtVCokjU smSKxrVTwpilflNxovX0VFFcffvYepjTRyisi7Z2iDCcnIeXc6hLrq8M11iWpyoEbm9F rkXHBlnKGYo8hI9qm0suGQJFk5n00y+xiFHWeURs+15rkAmJ6QpjKLL3xKlTTTWFkyfD +KJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775074082; x=1775678882; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EmReYcYw9J6Amp1NheLT+ENxqbKCjHRzmz5M8om8UX8=; b=QSh+kyajBXuGhpra1CU+r4RuEOjmx4djOBiV46R2NtMXMzqCXQsN5PURViE9bs1xFf DiBfJOGPbCoE0Eq45IR0hr1rZsmWdfWmi1onlbY0nw/Ltn9XPXOL5JN7x/PicYHrECMq NyAFGw6QkNXW6UXIAMlWaqQhaKphH2puYzPtpJurygCnH2F2zFoFo5icK4w96f2CUw8n qyDkZsIKsLcub0ILWB6JrSrLC+D0ioFfDncUw0w+S68vjJqIAulvIzYoNDnaG4SX86nO LY8GhrAY+xqxrQHC7ES86tGFOpPyWcTaQRDXBrwHdUjRGP2tdve6hArU2TH98PAXdaEV xMsA== X-Forwarded-Encrypted: i=1; AJvYcCXu7v/YyJMG+nFkFfO8uJvPmnaB35GAsnpxnDQtHLfFbcaiyVYbeixCXTKCxRnOLZflIQHMdkzohDorKpj3@lists.postgresql.org X-Gm-Message-State: AOJu0Yzb3+DfVcJR9wi2LcChJHwVmciKyX4zCHoYIvigeQvgVTaCh6gV 4hI+jzZ/SvKZHTfidWMN8YuRRqlTU+4eWr6YY5dA6LUVGoWynBOybvZYp0pE7CKQ5KcfWgWmZzi n6tAREhqrY161oAZRLWkMAFdJPkkAX8I= X-Gm-Gg: ATEYQzwi0UGXl5Ke1NR3ffCdaVtsb0jOF+pAm9lNtSe/Qw7Ox53cT3iilUghXKv+jz9 u3QVv7YfP8g4Zt9oKlqk/VS1D8VlssFsXulRXsvsZMDurypM4OyRi8GhEN1E9rbySn3aEGylsbE vC5mlBTrrLytpFMvNL1XSwKado6Mr2BiImG+ek1p6ptGEuWd9MNXd74XHPEkt23FMAjFHpyCPcy fz2xGEOl4P7dAu0CJeM2EAtVnu4tVt3XRWpjhJ3puh/5AW7ZoC1o9OUIH/ELAHuPhYUoSq+kyDS L6iagxk80u7RH8WyPdjiwuApKveI1AUOaGXKYj/yqUgSCWWx/cE3h98tqNfO7uakxVjNY3wdxaQ MJrFmS3MEUejLfC2Djv9lv5ec X-Received: by 2002:a05:7022:e1d:b0:119:e569:f875 with SMTP id a92af1059eb24-12be6874517mr2436807c88.18.1775074081906; Wed, 01 Apr 2026 13:08:01 -0700 (PDT) MIME-Version: 1.0 References: <5ae9578e-f25e-49c5-97ab-ad27bc2050b5@eisentraut.org> <5221f892-e1d5-4943-a3dc-5c9c7bdf4924@eisentraut.org> In-Reply-To: From: Corey Huinker Date: Wed, 1 Apr 2026 16:07:49 -0400 X-Gm-Features: AQROBzDafrvrcN9rn09Xqycs3-h8wdc8uagwcHyqak2LDbqcvN89oMZ4-Sn1L24 Message-ID: Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: jian he Cc: Amul Sul , Peter Eisentraut , Kirill Reshke , Vik Fearing , Isaac Morland , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000001a232c064e6ba491" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001a232c064e6ba491 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 1, 2026 at 3:23=E2=80=AFAM jian he wrote: > One more issue I found: > > https://git.postgresql.org/cgit/postgresql.git/commit/?id=3D74c96699be3f5= 3c058c8794c07952221b9625b4f > SELECT JSON_VALUE(jsonb '1234', '$' RETURNING char(2) DEFAULT '011' ON > ERROR); > ERROR: value too long for type character(2) > > Similarly, we can > SELECT CAST(text '1234' as char(2) DEFAULT '111111' ON conversion ERROR); > ERROR: value too long for type character(2) > Both of these are doomed when we hit the default, so I don't see why we should make any accommodation for them. > Composite types respect typmod, for example: > CREATE TYPE comp AS (a char(3), b int); > SELECT CAST('(14,42)' AS comp DEFAULT '(1234,2)' ON CONVERSION ERROR); -- > error > This one is trickier, but I'd be willing to reject composite inputs in v19 and solve it in v20. > The regression tests are too large; we can order them by the cast > source type's pg_type.type category, > so we won't miss any tests. > We can always remove redundant tests later. --0000000000001a232c064e6ba491 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Apr 1, 2026 at 3:23=E2=80=AFAM jian h= e <jian.universality@gmai= l.com> wrote:
One more issue I found:
= https://git.postgresql.org/cgit/postgresql.git/commit/?id=3D74c96699be3f53c= 058c8794c07952221b9625b4f
SELECT JSON_VALUE(jsonb '1234', '$' RETURNING char(2)=C2=A0= DEFAULT '011' ON ERROR);
ERROR:=C2=A0 value too long for type character(2)

Similarly, we can
SELECT CAST(text '1234' as char(2) DEFAULT '111111' ON conv= ersion ERROR);
ERROR:=C2=A0 value too long for type character(2)

=
Both of these are doomed when we hit the default, so I don't= see why we should make any accommodation for them.

=C2=A0
Composite types respect typmod, for example:
CREATE TYPE comp AS (a char(3), b int);
SELECT CAST('(14,42)' AS comp DEFAULT '(1234,2)' ON CONVERS= ION ERROR); -- error

This one is tricki= er, but I'd be willing to reject composite inputs in v19 and solve it i= n v20.
=C2=A0
The regression tests are too large; we can order them by the cast
source type's pg_type.type category,
so we won't miss any tests.

We can = always remove redundant tests later.
--0000000000001a232c064e6ba491--