Created
October 22, 2018 11:28
-
-
Save robinsmidsrod/5e847153633253225b74132310bd40b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION public.datatype_or_null(data anyelement, datatype text) | |
RETURNS anyelement | |
LANGUAGE plpgsql IMMUTABLE | |
AS $$ | |
BEGIN | |
RETURN CAST(data AS datatype); | |
EXCEPTION | |
WHEN OTHERS THEN | |
RETURN CAST(NULL AS datatype); | |
END; | |
$$; | |
select datatype_or_null('123'::text, 'integer'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment