Anton
Anton

Reputation: 313

How do I get a string value from its hex in PostgreSQL?

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'?

Upvotes: 4

Views: 9915

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 248175

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)

Upvotes: 7

Related Questions