All Products
Search
Document Center

PolarDB:Full-width and half-width character conversion functions (TO_SINGLE_BYTE and TO_MULTI_BYTE)

Last Updated:Mar 30, 2026

PolarDB for PostgreSQL (Compatible with Oracle) supports the Oracle-compatible TO_SINGLE_BYTE and TO_MULTI_BYTE functions via the polar_to_single_byte extension. TO_SINGLE_BYTE converts multibyte characters (such as fullwidth digits and letters) to their single-byte equivalents. TO_MULTI_BYTE does the reverse. These functions are not part of standard PostgreSQL; they are provided as an extension to maintain Oracle compatibility.

Prerequisites

Whether the extension is available depends on when your cluster was created:

  • Clusters created on or after March 30, 2020: The extension is created automatically when you create a database. No additional steps are required.

  • Clusters created before March 30, 2020: The extension is not created automatically. After creating a database, run the following statement to install it:

    CREATE EXTENSION polar_to_single_byte;

For the original Oracle function specifications, see the TO_SINGLE_BYTE and TO_MULTI_BYTE references in the Oracle documentation.

Supported data types

Both functions accept the following input types and return the same type as the input.

Function Input type Output type
TO_SINGLE_BYTE CHAR CHAR
TO_SINGLE_BYTE CHARACTER VARYING CHARACTER VARYING
TO_SINGLE_BYTE TEXT TEXT
TO_MULTI_BYTE CHAR CHAR
TO_MULTI_BYTE CHARACTER VARYING CHARACTER VARYING
TO_MULTI_BYTE TEXT TEXT

Examples

TO_SINGLE_BYTE

Convert a fullwidth string to ASCII:

SELECT to_single_byte('123$test');
 to_single_byte
----------------
 123$test
(1 row)

TO_MULTI_BYTE

Convert an ASCII string to fullwidth:

SELECT to_multi_byte('123$test');
  to_multi_byte
------------------
 123$test
(1 row)