Revision 13135
Added by Aaron Marcuse-Kubitza over 10 years ago
util.sql | ||
---|---|---|
3860 | 3860 |
|
3861 | 3861 |
|
3862 | 3862 |
-- |
3863 |
-- Name: try_cast(text, anyelement); Type: FUNCTION; Schema: util; Owner: - |
|
3864 |
-- |
|
3865 |
|
|
3866 |
CREATE FUNCTION try_cast(value text, ret_type_null anyelement) RETURNS anyelement |
|
3867 |
LANGUAGE plpgsql IMMUTABLE |
|
3868 |
AS $$ |
|
3869 |
BEGIN |
|
3870 |
/* need explicit cast because some types not implicitly-castable, and also |
|
3871 |
to make the cast happen inside the try block. (*implicit* casts to the |
|
3872 |
return type happen at the end of the function, outside any block.) */ |
|
3873 |
RETURN util.cast(value, ret_type_null); |
|
3874 |
EXCEPTION |
|
3875 |
WHEN data_exception THEN |
|
3876 |
PERFORM util.raise('WARNING', SQLERRM); |
|
3877 |
RETURN NULL; |
|
3878 |
END; |
|
3879 |
$$; |
|
3880 |
|
|
3881 |
|
|
3882 |
-- |
|
3883 |
-- Name: FUNCTION try_cast(value text, ret_type_null anyelement); Type: COMMENT; Schema: util; Owner: - |
|
3884 |
-- |
|
3885 |
|
|
3886 |
COMMENT ON FUNCTION try_cast(value text, ret_type_null anyelement) IS ' |
|
3887 |
ret_type_null: NULL::ret_type |
|
3888 |
'; |
|
3889 |
|
|
3890 |
|
|
3891 |
-- |
|
3863 | 3892 |
-- Name: try_create(text); Type: FUNCTION; Schema: util; Owner: - |
3864 | 3893 |
-- |
3865 | 3894 |
|
Also available in: Unified diff
schemas/util.sql: added try_cast()