SQL Server has CHAR ( integer_expression )
, so I can do
SELECT CHAR(65)
What is the equivalent on Postgresql? I have tried SELECT E'0円x65';
but I get
ERROR: invalid byte sequence for encoding "UTF8": 0x00
1 Answer 1
Have a look at the docs on PostgreSQL String Functions and Operators,
chr(int)
Character with the given code. ForUTF8
the argument is treated as a Unicode code point. For other multibyte encodings the argument must designate anASCII
character. TheNULL
(0)
character is not allowed because text data types cannot store such bytes.
Demonstrating chr()
, its inverse, and both.,
# SELECT chr(65), ascii('A'), chr(ascii('A'));
chr | ascii | chr
-----+-------+-----
A | 65 | A
(1 row)
In your question you use E''
(the "bytea Hex Format") which is totally possible too, though I wouldn't suggest it for simple problems like this. You can do that like this,
SELECT E'\x41'; -- 41 is hex for 65 (in base 10)
SELECT E'101円'; -- 101 is octal for 65 (in base 10)
?column?
----------
A
(1 row)
Explore related questions
See similar questions with these tags.
92
(which is different from 0x92). Or, perhaps you do mean 0x92 which is valid in Win1252 but would require reencoding. Because that's a fundamentally different problem I'm going to alter your question to use 65 which is ASCII forA
.