| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Michał Wadas <michalwadas(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Proposal: is_castable |
| Date: | 2020-04-03 14:19:20 |
| Message-ID: | 23154.1585923560@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
=?UTF-8?Q?Micha=C5=82_Wadas?= <michalwadas(at)gmail(dot)com> writes:
> Currently there is no way to check if CAST will succeed.
> Therefore I propose adding new function: is_castable
> SELECT is_castable('foo' as time) // false
What would you actually do with it?
> Similar features are implemented in:
> - SQL Server (as TRY_CONVERT)
> - Oracle (as CONVERT([val] DEFAULT [expr] ON CONVERSION ERROR)
Somehow, I don't think those have the semantics of what you suggest here.
I suspect you are imagining that you could write something like
CASE WHEN is_castable(x as y) THEN cast(x as y) ELSE ...
but that will not work. The THEN condition has to pass parse analysis
whether or not execution will ever reach it.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2020-04-03 14:19:21 | where should I stick that backup? |
| Previous Message | Amit Kapila | 2020-04-03 14:06:26 | Re: WAL usage calculation patch |