0

In PostgreSQL, let's say I have the following table:

+-------+---------+
|       | someVal |
| myInt |         |
+-------+---------+
| 123   | a       |
+-------+---------+
| 456   | b       |
+-------+---------+
| 789   | c       |
+-------+---------+

I want to convert the myInt column into a formatted string that contains the hex representation of the integer in it and rename the column. So it would look something like the following:

+----------+---------+
|          | someVal |
| myHex    |         |
+----------+---------+
| hex: 7B  | a       |
+----------+---------+
| hex: 1C8 | b       |
+----------+---------+
| hex: 315 | c       |
+----------+---------+

What would the query look like to convert the integer?

1
  • Please show us what you tried and where you got stuck. Commented May 8, 2020 at 3:00

1 Answer 1

2

Try the following in PostgreSQL.

select
   concat('hex: ', cast(to_hex(ms) as text)) as myHex,
   someVal
from yourTable
Sign up to request clarification or add additional context in comments.

1 Comment

I want it to be a string with that hex interpolated inside of it.

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.