We are migrating our database from Postgres to Redshift and we are having some challenges with converting Base64 string to Hex.
In the old situation (in postgres) we have a function :
CREATE OR REPLACE FUNCTION hex_to_int(hexval character varying)
RETURNS integer
LANGUAGE plpgsql
IMMUTABLE STRICT
AS $$
DECLARE
result int;
BEGIN
EXECUTE 'SELECT x''' || hexval || '''::int' INTO result;
RETURN result;
END;
$$
And we call this in the select:
SELECT
encode(decode('AQDAAi0EAAoFAAcN5A=='::text, 'base64'::text), 'hex'::text) AS hexresult
FROM table
The result is shown as: 0100c0022d04000a0500070de4
Redshift does not seem to support plpgsql functions, now looking for a different way to do this.
I have tried to do this with base64.b64decode
As a result I see: