create function hex(text) returns text language sql immutable strict as $$
select encode($1::bytea, 'hex')
$$;
create function hex(bigint) returns text language sql immutable strict as $$
select to_hex($1)
$$;
create function unhex(text) returns text language sql immutable strict as $$
select encode(decode($1, 'hex'), 'escape')
$$;
select hex('abc'), hex(123), unhex(hex('PostgreSQL'));
Výsledek:
╔════════╤═════╤════════════╗ ║ hex │ hex │ unhex ║ ╠════════╪═════╪════════════╣ ║ 616263 │ 7b │ PostgreSQL ║ ╚════════╧═════╧════════════╝
Je to PostgreSQL:všechno možné :)