=?UTF-8?Q?Micha=C5=82_Wadas?= <michalwa...@gmail.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


Reply via email to