CREATE OR REPLACE FUNCTION sha1(bytea) returns text AS $$ SELECT encode(digest($1, 'sha1'), 'hex') $$ LANGUAGE SQL STRICT IMMUTABLE;
While this is a great example, it may expose a database app to vulnerabilities if the attacker succeeds in overriding the function sha1(...) in the app's user context (schema)