Re: Better performance no-throw conversion?

Поиск
Список
Период
Сортировка
От Andrew Dunstan
Тема Re: Better performance no-throw conversion?
Дата
Msg-id 7f9b14e3-02e3-4c88-b187-a2f8595de6f6@dunslane.net
обсуждение исходный текст
Ответ на Better performance no-throw conversion?  ("ldh@laurent-hasson.com" <ldh@laurent-hasson.com>)
Ответы RE: Better performance no-throw conversion?  ("ldh@laurent-hasson.com" <ldh@laurent-hasson.com>)
Список pgsql-performance
On 9/8/21 1:17 PM, ldh@laurent-hasson.com wrote:
>
> Hello,
>
>  
>
> Some databases such as SQLServer (try_cast) or BigQuery (safe.cast)
> offer not-throw conversion. In general, these tend to perform better
> than custom UDFs that catch exceptions and are also simpler to use.
> For example, in Postgres, I have a function that does the following:
>
>  
>
> CREATE OR REPLACE FUNCTION toFloat(str varchar, val real)
>
> RETURNS real AS $$
>
> BEGIN
>
>   RETURN case when str is null then val else str::real end;
>
> EXCEPTION WHEN OTHERS THEN
>
>   RETURN val;
>
> END;
>
> $$ LANGUAGE plpgsql COST 1 IMMUTABLE;
>
>  
>
> I couldn’t find a reference to such capabilities in Postgres and
> wondered if I missed it, and if not, is there any plan to add such a
> feature?
>
>  
>


Not that I know of, but you could probably do this fairly simply in C.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com




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

Предыдущее
От: "ldh@laurent-hasson.com"
Дата:
Сообщение: Better performance no-throw conversion?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Better performance no-throw conversion?