Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/ref/create_conversion.sgml`
21e882fd75a0cfe9c29e88cb0fc2bb89cdac95f53aaa35660000000100000e48
 indicates that this conversion
       is the default for this particular source to destination
       encoding. There should be only one default encoding in a schema
       for the encoding pair.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><replaceable>name</replaceable></term>

     <listitem>
      <para>
       The name of the conversion. The conversion name can be
       schema-qualified. If it is not, the conversion is defined in the
       current schema. The conversion name must be unique within a
       schema.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><replaceable>source_encoding</replaceable></term>

     <listitem>
      <para>
       The source encoding name.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><replaceable>dest_encoding</replaceable></term>

     <listitem>
      <para>
       The destination encoding name.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><replaceable>function_name</replaceable></term>

     <listitem>
      <para>
       The function used to perform the conversion.  The function name can
       be schema-qualified.  If it is not, the function will be looked
       up in the path.
      </para>

      <para>
       The function must have the following signature:

<programlisting>
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;
</programlisting>
       The return value is the number of source bytes that were successfully
       converted. If the last argument is false, the function must throw an
       error on invalid input, and the return value is always equal to the
       source string length.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
 </refsect1>

 <refsect1 id="sql-createconversion-notes">
  <title>Notes</title>

  <para>
   Neither the source nor the destination encoding can
   be <literal>SQL_ASCII</literal>, as the server's behavior for cases
   involving the <literal>SQL_ASCII</literal> <quote>encoding</quote> is
   hard-wired.
  </para>

  <para>
   Use <command>DROP CONVERSION</command> to remove user-defined conversions.
  </para>

  <para>
   The privileges required to create a conversion might be changed in a future
   release.
  </para>
 </refsect1>

 <refsect1 id="sql-createconversion-examples">
  <title>Examples</title>

  <para>
   To create a conversion from encoding <literal>UTF8</literal> to
   <literal>LATIN1</literal> using <function>myfunc</function>:
<programlisting>
CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;
</programlisting></para>
 </refsect1>


 <refsect1 id="sql-createconversion-compat">
  <title>Compatibility</title>

  <para>
    <command>CREATE CONVERSION</command>
    is a <productname>PostgreSQL</productname> extension.
    There is no <command>CREATE CONVERSION</command>
    statement in the SQL standard, but a <command>CREATE TRANSLATION</command>
    statement that is very similar in purpose and syntax.
  </para>
 </refsect1>


 <refsect1 id="sql-createconversion-seealso">
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-alterconversion"/></member>
   <member><xref linkend="sql-createfunction"/></member>
   <member><xref linkend="sql-dropconversion"/></member>
  </simplelist>
 </refsect1>

</refentry>

Title: CREATE CONVERSION: Parameters, Notes, Examples, and Compatibility
Summary
This section details the parameters for the CREATE CONVERSION command, including DEFAULT, name, source_encoding, dest_encoding, and function_name, along with the required function signature. It notes that neither encoding can be SQL_ASCII and refers to DROP CONVERSION for removing conversions. It provides an example of creating a conversion and notes that CREATE CONVERSION is a PostgreSQL extension, similar in purpose to SQL's CREATE TRANSLATION.