2 .\" Title: CREATE CONVERSION
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "CREATE CONVERSION" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 CREATE_CONVERSION \- define a new encoding conversion
35 CREATE [ DEFAULT ] CONVERSION \fIname\fR
36 FOR \fIsource_encoding\fR TO \fIdest_encoding\fR FROM \fIfunction_name\fR
40 \fBCREATE CONVERSION\fR
41 defines a new conversion between two character set encodings\&.
43 Conversions that are marked
45 can be used for automatic encoding conversion between client and server\&. To support that usage, two conversions, from encoding A to B
47 from encoding B to A, must be defined\&.
49 To be able to create a conversion, you must have
51 privilege on the function and
53 privilege on the destination schema\&.
60 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\&.
65 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\&.
70 The source encoding name\&.
75 The destination encoding name\&.
80 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\&.
82 The function must have the following signature:
89 integer, \-\- source encoding ID
90 integer, \-\- destination encoding ID
91 cstring, \-\- source string (null terminated C string)
92 internal, \-\- destination (fill with a null terminated C string)
93 integer, \-\- source string length
94 boolean \-\- if true, don\*(Aqt throw an error if conversion fails
101 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\&.
105 Neither the source nor the destination encoding can be
106 SQL_ASCII, as the server\*(Aqs behavior for cases involving the
112 \fBDROP CONVERSION\fR
113 to remove user\-defined conversions\&.
115 The privileges required to create a conversion might be changed in a future release\&.
118 To create a conversion from encoding
129 CREATE CONVERSION myconv FOR \*(AqUTF8\*(Aq TO \*(AqLATIN1\*(Aq FROM myfunc;
136 \fBCREATE CONVERSION\fR
139 extension\&. There is no
140 \fBCREATE CONVERSION\fR
141 statement in the SQL standard, but a
142 \fBCREATE TRANSLATION\fR
143 statement that is very similar in purpose and syntax\&.
145 ALTER CONVERSION (\fBALTER_CONVERSION\fR(7)), CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7)), DROP CONVERSION (\fBDROP_CONVERSION\fR(7))