All Products
Search
Document Center

PolarDB:CREATE CONVERSION

Last Updated:Mar 28, 2026

Defines a new encoding conversion between two character set encodings.

Synopsis

CREATE [ DEFAULT ] CONVERSION name
    FOR source_encoding TO dest_encoding FROM function_name

Description

CREATE CONVERSION registers a function that converts data between two character set encodings.

Mark a conversion as DEFAULT to use it for automatic encoding conversion between client and server. To support automatic conversion for an encoding pair, define two conversions: one from encoding A to B, and one from encoding B to A.

To create a conversion, you must have:

  • EXECUTE privilege on the conversion function

  • CREATE privilege on the destination schema

Parameters

DEFAULT

Marks this conversion as the default for the specified source-to-destination encoding pair. Only one default conversion per encoding pair is allowed within a schema.

name

The name of the conversion. Schema-qualify the name to create the conversion in a specific schema; otherwise, it is created in the current schema. The name must be unique within the schema.

source_encoding

The source encoding name.

dest_encoding

The destination encoding name.

function_name

The function that performs the conversion. Schema-qualify the name to specify a function in a particular schema; otherwise, the function is looked up using the search path.

The function must have the following signature:

conv_proc(
    integer,  -- source encoding ID
    integer,  -- destination encoding ID
    cstring,  -- source string (null-terminated C string)
    internal, -- destination (fill with a null-terminated C string)
    integer,  -- source string length
    boolean   -- if true, don't throw an error if conversion fails
) RETURNS integer;

Usage notes

  • Neither the source nor the destination encoding can be SQL_ASCII. The server's behavior for cases involving the SQL_ASCII encoding is hard-wired.

  • To remove a user-defined conversion, use DROP CONVERSION.

  • The privileges required to create a conversion might change in a future release.

Examples

Create a conversion named myconv from UTF8 to LATIN1 using the function myfunc:

CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;