Better performance no-throw conversion? - Mailing list pgsql-performance

From ldh@laurent-hasson.com
Subject Better performance no-throw conversion?
Date
Msg-id MN2PR15MB2560C23261EFFBFC9F437A5B85D49@MN2PR15MB2560.namprd15.prod.outlook.com
Whole thread Raw
Responses Re: Better performance no-throw conversion?  (Andrew Dunstan <andrew@dunslane.net>)
Re: Better performance no-throw conversion?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-performance

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?

 

Thank you!

Laurent Hasson.

pgsql-performance by date:

Previous
From: Stepan Yankevych
Date:
Subject: Foreign table as partition - Non optimal aggregation plan
Next
From: Andrew Dunstan
Date:
Subject: Re: Better performance no-throw conversion?