4

I have a string value of '2.4.3369.6'. Using the command: select encode('2.4.3369.6', 'hex') as string_to_hex

I translate this value into a hex and get the next value of

'322e342e333336392e36'

Which command or commands do I use to get the value '2.4.3369.6' from the value '322e342e333336392e36'?

3
  • 1
    In case anyone's wondering, decode('322e342e333336392e36','hex') doesn't work. Commented Jun 26, 2018 at 9:15
  • Everything works, thank you. Just my editor (pgadmin) why that values were not displayed! Commented Jun 26, 2018 at 9:18
  • select '2.4.3369.6' as string_in_dec, encode('2.4.3369.6', 'hex') as string_to_hex, convert_from(decode('322e342e333336392e36','hex'),'UTF-8') as string_to_dec; Commented Jun 26, 2018 at 9:28

1 Answer 1

7

Assuming that the encoding is UTF8, you could use the following to get it as text:

SELECT convert_from(decode('322e342e333336392e36','hex'), 'UTF8');

┌──────────────┐
│ convert_from │
├──────────────┤
│ 2.4.3369.6   │
└──────────────┘
(1 row)
Sign up to request clarification or add additional context in comments.

2 Comments

Is there a postgres 12 compatible function for this ? I have scoured through the docs to no avail. Thanks!
@YY That works fine in v12, I just tried.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.