PostgreSQL – CHR Function

The CHR function is used to return the character corresponding to a specified ASCII code or Unicode code point. It’s a convenient way to generate characters based on their numeric representations.

The syntax of the CHR function is as follows:

CHR(code)

where code is the numeric code that represents the character you want to retrieve.

Here’s an example of how you might use the CHR function in a SQL query:

SELECT CHR(65) AS character;

In this example, the result would be the character 'A', as the numeric code 65 corresponds to the ASCII code for the uppercase letter 'A'.

You can also use the CHR function with Unicode code points:

SELECT CHR(9731) AS emoji;

In this case, the result would be the character '☃', which is a snowman emoji. The Unicode code point 9731 represents this particular emoji character.

The CHR function is particularly useful when you need to include special characters or symbols in your SQL queries or reports. Just make sure to use the appropriate code point for the character you want to generate.

Similar Posts