postgresql/doc/src/sgml/ref/create_conversion.sgml

172 lines
4.5 KiB
Plaintext
Raw Normal View History

<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/create_conversion.sgml,v 1.23 2010/04/03 07:22:58 petere Exp $ -->
<refentry id="SQL-CREATECONVERSION">
<refmeta>
<refentrytitle>CREATE CONVERSION</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>CREATE CONVERSION</refname>
<refpurpose>define a new encoding conversion</refpurpose>
</refnamediv>
2003-08-31 19:32:24 +02:00
<indexterm zone="sql-createconversion">
<primary>CREATE CONVERSION</primary>
</indexterm>
<refsynopsisdiv>
<synopsis>
CREATE [ DEFAULT ] CONVERSION <replaceable>name</replaceable>
FOR <replaceable>source_encoding</replaceable> TO <replaceable>dest_encoding</replaceable> FROM <replaceable>function_name</replaceable>
</synopsis>
</refsynopsisdiv>
<refsect1 id="sql-createconversion-description">
<title>Description</title>
<para>
<command>CREATE CONVERSION</command> defines a new conversion between
character set encodings. Also, conversions that
are marked <literal>DEFAULT</> can be used for automatic encoding
conversion between
2003-04-22 12:08:08 +02:00
client and server. For this purpose, two conversions, from encoding A to
B <emphasis>and</emphasis> from encoding B to A, must be defined.
</para>
<para>
2003-04-22 12:08:08 +02:00
To be able to create a conversion, you must have <literal>EXECUTE</literal> privilege
on the function and <literal>CREATE</literal> privilege on the destination schema.
</para>
2003-04-22 12:08:08 +02:00
</refsect1>
2003-04-22 12:08:08 +02:00
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><literal>DEFAULT</literal></term>
<listitem>
<para>
The <literal>DEFAULT</> clause 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>
2003-04-22 12:08:08 +02:00
<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.
2003-04-22 12:08:08 +02:00
</para>
2003-04-22 12:08:08 +02:00
<para>
The function must have the following signature:
2003-04-22 12:08:08 +02:00
<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)
2003-04-22 12:08:08 +02:00
integer -- source string length
) RETURNS void;
</programlisting>
</para>
</listitem>
</varlistentry>
</variablelist>
2003-04-22 12:08:08 +02:00
</refsect1>
<refsect1 id="sql-createconversion-notes">
<title>Notes</title>
<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
2003-04-22 12:08:08 +02:00
<literal>LATIN1</literal> using <function>myfunc</>:
<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.
2002-07-22 15:00:00 +02:00
There is no <command>CREATE CONVERSION</command>
2003-04-22 12:08:08 +02:00
statement in the SQL standard.
</para>
</refsect1>
<refsect1 id="sql-createconversion-seealso">
<title>See Also</title>
2003-06-27 16:45:32 +02:00
<simplelist type="inline">
<member><xref linkend="sql-alterconversion"></member>
<member><xref linkend="sql-createfunction"></member>
<member><xref linkend="sql-dropconversion"></member>
2003-06-27 16:45:32 +02:00
</simplelist>
</refsect1>
</refentry>