Sha256: a68e502d8aa58521f45487365fb9fe5c09ac34e5ca6387b7692755b72de3512c

Contents?: true

Size: 709 Bytes

Versions: 15

Compression:

Stored size: 709 Bytes

Contents

-- Note there is already a convert_to_float function but that remains untouched - this version
-- has different arguments so is a new (overlaoded) function.
CREATE OR REPLACE FUNCTION renalware.convert_to_float(v_input text, default_value_if_cannot_be_coerced float)
RETURNS float AS $$
DECLARE v_float_value float DEFAULT NULL;
BEGIN
    BEGIN
        v_float_value := v_input::float;
    EXCEPTION WHEN OTHERS THEN
        RETURN default_value_if_cannot_be_coerced;
    END;
RETURN v_float_value;
END;
$$ LANGUAGE plpgsql;

COMMENT ON FUNCTION renalware.convert_to_float(text, float) IS
'Tries to coerce v_input into a float (double precision) and it it cannot,
returns default_value_if_cannot_be_coerced';

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
renalware-core-2.1.1 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.1.0 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.167 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.166 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.165 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.164 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.163 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.162 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.161 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.160 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.159 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.158 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.157 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.156 db/functions/convert_to_float_with_explicit_return_v01.sql
renalware-core-2.0.155 db/functions/convert_to_float_with_explicit_return_v01.sql