Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions

From: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Amul Sul <sulamul(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions
Date: 2026-04-01 20:07:49
Message-ID: CADkLM=c_QQkpBhm0HfGm5C8gOFNKW6g5E=W5Jp9mjayUW3yXYQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Apr 1, 2026 at 3:23 AM jian he <jian(dot)universality(at)gmail(dot)com> wrote:

> One more issue I found:
>
> https://git.postgresql.org/cgit/postgresql.git/commit/?id=74c96699be3f53c058c8794c07952221b9625b4f
> 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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-04-01 20:20:10 Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE
Previous Message Masahiko Sawada 2026-04-01 19:38:23 Re: Introduce XID age based replication slot invalidation