Suggestion: optionally return default value instead of error on failed cast

Поиск
Список
Период
Сортировка
От Wolfgang Walther
Тема Suggestion: optionally return default value instead of error on failed cast
Дата
Msg-id 33f8ec59-635f-8e65-e960-ccba355247d2@technowledgy.de
обсуждение исходный текст
Ответы Re: Suggestion: optionally return default value instead of error on failed cast  (Corey Huinker <corey.huinker@gmail.com>)
Re: Suggestion: optionally return default value instead of error on failed cast  (Mark Simon <mark@manngo.net>)
Список pgsql-hackers
Hi,

currently a failed cast throws an error. It would be useful to have a 
way to get a default value instead.

T-SQL has try_cast [1]
Oracle has CAST(... AS .. DEFAULT ... ON CONVERSION ERROR) [2]

The DEFAULT ... ON CONVERSION ERROR syntax seems like it could be 
implemented in PostgreSQL. Even if only DEFAULT NULL was supported (at 
first) that would already help.

The short syntax could be extended for the DEFAULT NULL case, too:

SELECT '...'::type -- throws error
SELECT '...':::type -- returns NULL

I couldn't find any previous discussion on this, please advise in case I 
just missed it.

Thoughts?

Best

Wolfgang

[1]: 
https://docs.microsoft.com/en-us/sql/t-sql/functions/try-cast-transact-sql
[2]: 
https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/CAST.html



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly
Следующее
От: Etsuro Fujita
Дата:
Сообщение: Re: Asynchronous Append on postgres_fdw nodes.