When you migrate applications from Oracle to PolarDB, code containing Oracle-specific TRANSLATE ... USING syntax may fail to execute. To simplify migrations, PolarDB is now compatible with this syntax, allowing existing code to run without modification.
Applicability
Your PolarDB for PostgreSQL (Compatible with Oracle) cluster must run minor engine version 2.0.14.18.37.0 or later.
You can view the minor engine version in the console or run the SHOW polardb_version; statement. If your cluster does not meet the version requirement, upgrade the minor engine version.
How it works
TRANSLATE ... USING is intended only for Oracle syntax compatibility, not for providing equivalent functionality.
Dimension | Oracle | PolarDB (Key differences) |
Main purpose | Performs character encoding conversion between the database character set | Used only for syntax compatibility. Ensures that code containing this syntax can be parsed and executed successfully. |
Conversion behavior | Performs a byte-level conversion. | No character set conversion occurs. The expression behaves like a |
| Converts the expression to the database character set and returns | Returns the |
| Converts the expression to the national character set and returns | Returns the |
Examples
Verify syntax compatibility
Verify that the TRANSLATE USING expression does not alter the content of a string, even when it contains multi-byte characters (like Chinese).
Run the following SQL statement:
SELECT
TRANSLATE('Hello, PolarDB' USING CHAR_CS) AS result_char_cs,
TRANSLATE('Hello, PolarDB' USING NCHAR_CS) AS result_nchar_cs;Expected result
The two columns in the result are identical. This proves that the CHAR_CS and NCHAR_CS clauses have no functional difference in PolarDB.
result_char_cs | result_nchar_cs
----------------+-----------------
Hello, PolarDB | Hello, PolarDBPerform an actual character set conversion
To perform an actual character set encoding conversion, such as from UTF8 to LATIN1, do not use TRANSLATE USING. Instead, use the standard CONVERT() function.