Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 419
Anton Avatar asked Nov 03 '25 11:11

Anton


1 Answers

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)
like image 179
Laurenz Albe Avatar answered Nov 06 '25 03:11

Laurenz Albe