Created
June 13, 2011 09:02
-
-
Save ozzyaaron/1022494 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
def self.up | |
function_string = 'CREATE OR REPLACE FUNCTION searchable_number(v_input text) | |
RETURNS numeric AS $$ | |
DECLARE v_numeric_value numeric DEFAULT NULL; | |
BEGIN | |
BEGIN | |
v_numeric_value := v_input::NUMERIC; | |
EXCEPTION WHEN OTHERS THEN | |
RAISE NOTICE \'Invalid numeric value: "%". Returning NULL.\', v_input; | |
RETURN NULL; | |
END; | |
RETURN v_numeric_value; | |
END; | |
$$ LANGUAGE plpgsql;' | |
execute function_string | |
function_string = 'CREATE OR REPLACE FUNCTION searchable_datetime(v_input text) | |
RETURNS timestamp AS $$ | |
DECLARE v_timestamp_value timestamp DEFAULT NULL; | |
BEGIN | |
BEGIN | |
v_timestamp_value := v_input::TIMESTAMP; | |
EXCEPTION WHEN OTHERS THEN | |
RAISE NOTICE \'Invalid datetime value: "%". Returning NULL.\', v_input; | |
RETURN NULL; | |
END; | |
RETURN v_timestamp_value; | |
END; | |
$$ LANGUAGE plpgsql;' | |
execute function_string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment