# 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.

Leave a Reply

Related posts