PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Triggers
  • Views
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
    • Aggregate Functions
    • Date / Time Functions
    • String Functions
    • Math Functions
Home / PostgreSQL String Functions / PostgreSQL ASCII

PostgreSQL ASCII

The PostgreSQL ASCII() function returns an ASCII code value of a character. In the case of UTF-8, the ASCII() function returns the Unicode code point of the character.

Syntax

The following illustrates the syntax of ASCII function:

1
ASCII(char)

Arguments

The ASCII() function requires one argument:

1) char

The char argument is a character that you want to get the ASCII code.

If you pass a string to the ASCII() function, it will return the ASCII code of the first character.

Return value

The ASCII() function returns an integer that represents the ASCII code value of the input character. In the case of a UTF-8 character, it returns an integer which is corresponding to the Unicode code point.

Examples

The following example uses the ASCII() function to get the ASCII code values of character A and a:

1
2
3
SELECT
    ASCII( 'A' ),
    ASCII( 'a' );

The output is:

PostgreSQL ASCII function example

If you pass a sequence of characters to the ASCII() function, you will get the ASCII code of the first character as shown in the following example:

1
2
SELECT
    ASCII( 'ABC' );

The function returns the ASCII code of the letter A which is 65 as follows:

PostgreSQL ASCII function - string example

The following example illustrates how to use the ASCII() function to get the Unicode code point of a UTF-8 character:

1
2
SELECT
    ASCII( 'Ω' );

PostgreSQL ASCII function - unicode example

Remarks

To get the ASCII code value or Unicode code point of an integer, you use the CHR() function.

In this tutorial, you have learned how to use the PostgreSQL ASCII() function to get the ASCII code or Unicode code point of a character.

Next Tutorial: PostgreSQL CHR

PostgreSQL String Functions

  • ASCII
  • CONCAT
  • CHR
  • FORMAT
  • LEFT
  • LENGTH
  • LPAD
  • MD5
  • POSITION
  • REGEXP_MATCHES
  • REGEXP_REPLACE
  • RIGHT
  • REPLACE
  • SPLIT_PART
  • SUBSTRING
  • TRANSLATE
  • TRIM

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • PostgreSQL TRUNC
  • PostgreSQL ROUND
  • PostgreSQL Math Functions
  • PostgreSQL LOCALTIME
  • PostgreSQL LOCALTIMESTAMP
  • PostgreSQL CURRENT_TIMESTAMP
  • PostgreSQL CURRENT_TIME
  • PostgreSQL CURRENT_DATE
  • PostgreSQL Date Functions
  • PostgreSQL EXTRACT

More Tutorials

  • PostgreSQL Cheat Sheet
  • PostgreSQL Administration
  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2017 by PostgreSQL Tutorial Website. All Rights Reserved.