0

I want to use to_char function in Postgresql but take an error when execute the script.

Oracle version is ok;

to_char('7374961057827412212','XXXXXXXXXXXXXXXXXXXX') 

result : 66592002042458F4

But I could not find Postgresql version and take an error like this;

ERROR:  function to_char(text, unknown) does not exist

1 Answer 1

1

If you look at the table of formatting codes for numbers, you will see that X is not supported, and indeed there is no way to get hexadecimal output with to_char.

But you can use to_hex:

SELECT to_hex(7374961057827412212);

      to_hex      
══════════════════
 66592002042458f4
(1 row)

The error message you see is because you entered the first argument in single quotes, so it is a string (data type text), but there is no to_char function to format strings as strings (they are already strings).

Sign up to request clarification or add additional context in comments.

Comments

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.