ha, funny. I thought he was looking for something that acts like the oracle decode function. Now that I reread it, it is really talking about endcoding/decoding stuff. my bad
You can create your own "decode" function in pg like this example using varchars as input. Then simply create other overloaded "decode" functions for different input datatypes.
CREATE OR REPLACE FUNCTION decode(expr varchar, search varchar, result varchar, dflt varchar) RETURNS varchar AS
$$
BEGIN
CASE WHEN expr = search THEN RETURN result; ELSE RETURN dflt; END CASE;
END
$$ LANGUAGE plpgsql;
Am I the only one who cannot find anything related to the OP's question in this answer?
I found this on SO:
CREATEOR REPLACE FUNCTION decode_url_part(p varchar) RETURNSvarcharAS $$
SELECT convert_from(CAST(E'\\x'|| string_agg(CASEWHEN length(r.m[1]) =1THEN encode(convert_to(r.m[1], 'SQL_ASCII'), 'hex') ELSEsubstring(r.m[1] from2for2) END, '') AS bytea), 'UTF8')
FROM regexp_matches($1, '%[0-9a-f][0-9a-f]|.', 'gi') AS r(m);
$$ LANGUAGESQL IMMUTABLE STRICT;