Convert Hex to Decimal in Postgresql: Simple Tutorial

If you need to convert a hexadecimal value to decimal in Postgresql, it's actually quite easy. All you need to do is use the to_number() function and specify the base of the input value as 16 (since hexadecimal is base 16).

Here's an example query to convert a hexadecimal value (in this case, '1A') to decimal:


SELECT to_number('1A', 'XX');

In this example, 'XX' is used to specify the base of the input value as 16. The result of this query will be the decimal value of 26.

It's important to note that the input value must be a valid hexadecimal value. If the input value is not a valid hexadecimal value, the to_number() function will return an error.

In summary, to convert a hexadecimal value to decimal in Postgresql, use the to_number() function and specify the base of the input value as 16.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information