| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | assam258(at)gmail(dot)com |
| Cc: | corey(dot)huinker(at)gmail(dot)com, peter(at)eisentraut(dot)org, vik(at)postgresfriends(dot)org, sulamul(at)gmail(dot)com, reshkekirill(at)gmail(dot)com, 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-07-02 15:38:41 |
| Message-ID: | CACJufxEawrK+FhFzyWMPKZ_r11jEqbzq4soUM2ZRBNSintQ+AQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, Jul 2, 2026 at 10:06 PM Henson Choi <assam258(at)gmail(dot)com> wrote:
>>
>>
>> C. A nested DEFAULT can turn a hard error into a silent wrong answer.
>>
>> CREATE TABLE t(a text, b text);
>> INSERT INTO t VALUES ('foo', 'bar');
>>
>> SELECT CAST(CAST(a AS int DEFAULT b::int ON CONVERSION ERROR)
>> AS int2 DEFAULT -1 ON CONVERSION ERROR) FROM t;
>> -- -1
>>
>> The inner DEFAULT b::int (b = 'bar') fails at run time. At top level
>> the same failing DEFAULT raises:
>>
>> SELECT CAST('x' AS int DEFAULT ('zzz')::int ON CONVERSION ERROR);
>> -- ERROR: invalid input syntax for type integer: "zzz"
>>
>> Nested, it is instead taken for the outer cast's own conversion failure
>> and the outer DEFAULT (-1) is returned silently. A hard error becoming
>> a silent value is the concern here, independently of the DEFAULT policy
>> in (D).
>>
>>
For C:
I tried that in
https://www.postgresql.org/message-id/CACJufxH_1EtEBMb0JvxaM3Gmnt33HYrS37m5eYjJ_OfBkMVFJg%40mail.gmail.com
It seems infeasible to evaluate some subexpressions in an error-safe manner
while others are not. Therefore, if the top-level expression is error-safe, the
entire expression will compile to support error-safe evaluation for its
subexpressions as well.
For D, this is intended i suppose, see
https://www.postgresql.org/message-id/762ae707-7fdc-43d8-a77a-3a10d12ce21d%40postgresfriends.org
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-07-02 15:49:24 | Re: Truncate logs by max_log_size |
| Previous Message | Peter Eisentraut | 2026-07-02 15:13:50 | Re: implement CAST(expr AS type FORMAT 'template') |