I need to convert hexa to values and need to update the values in a varchar field, I have tried:

select pg_catalog.decode(column,'hex')

The above code converted hexa to values but when I try to update a varchar field I am getting an error:

column is a character varying and expression of type Bytea,

Casting with ::text also doesn't do it.

  • My downvote is for not declaring your database (Greenplum) in the question. Read the tag wiki of Postgres. – Erwin Brandstetter Dec 15 '14 at 1:22

To convert an hexadecimal string to characters, the encoding must be specified. This is necessary because the same series of bytes may produce different characters depending on their encoding.

For instance, if the hex codes represent an utf-8 string, use:

select convert_from(decode(your_hex_string, 'hex'), 'utf-8');

If the encoding is not supported by the built-in convert_from(), see UTF16 hex to text for several alternative conversion techniques.

| improve this answer | |
  • Thanks @Daniel , we are using Greenplum i coudn't find Convert_from function , Have any idea ? – William R Dec 11 '14 at 13:32
  • 1
    @WilliamR: no. Does that product have an online manual? – Daniel Vérité Dec 11 '14 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.