CREATE_CONVERSION(7pg17)
β¨ CREATE_CONVERSION π β bestie, let's define a whole new encoding conversion β¨
okay so this is the CREATE_CONVERSION(7) page from the PostgreSQL 17.11 documentation, and honestly? it's giving "niche but powerful" and i'm obsessed. buckle up, bestie π
β¨ SYNOPSIS β¨
like, here's the whole vibe in one line:
CREATE [ DEFAULT ] CONVERSION name
FOR source_encoding TO dest_encoding FROM function_name
πΈ DESCRIPTION πΈ
CREATE CONVERSION defines a brand-new conversion between two character set encodings. slay. that's literally the whole point π
conversions that are marked DEFAULT can be used for automatic encoding conversion between client and server. but here's the catch, bestie: to support that usage, you need two conversions defined β one from encoding A to B, and one from encoding B to A. it's giving "you can't just do one direction and call it a day" π
to be able to create a conversion, you must have EXECUTE privilege on the function and CREATE privilege on the destination schema. no cap, both. π
π¦ PARAMETERS π¦
DEFAULTβ this clause indicates that this conversion is the default for this particular source-to-destination encoding. lowkey important: there should be only one default encoding in a schema for the encoding pair. not two, not three, just one π«Άnameβ the name of the conversion. it can be schema-qualified. if it's not, the conversion is defined in the current schema. and the conversion name must be unique within a schema β no duplicates allowed, periodt β¨source_encodingβ the source encoding name. that's it. that's the girl πdest_encodingβ the destination encoding name. also that's it, she's serving πfunction_nameβ the function used to perform the conversion. the function name can be schema-qualified. if it's not, the function will be looked up in the path.
the function must have the following signature, and yes i'm copying it exactly because this part is sacred:
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;
the return value is the number of source bytes that were successfully converted. and here's the drama: 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. don't forget that part or it's gonna be a whole mess π
π§ NOTES π§
neither the source nor the destination encoding can beSQL_ASCII, because the server's behavior for cases involving theSQL_ASCII"encoding" is hard-wired. so like, don't even try it bestie, it's not gonna work π
use DROP CONVERSION to remove user-defined conversions. clean up after yourself, it's the main character thing to do π
the privileges required to create a conversion might be changed in a future release. so like, stay tuned i guess? π
π EXAMPLES π
to create a conversion from encoding UTF8 to LATIN1 using myfunc, you literally just do this:
CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;
ate and left no crumbs π β¨
π COMPATIBILITY π
CREATE CONVERSION is a PostgreSQL extension. there is no CREATE CONVERSION statement in the SQL standard. BUT there's a CREATE TRANSLATION statement that is very similar in purpose and syntax. so like, your fave is a little bit extra and off-script, and honestly? iconic behavior π
π SEE ALSO π
ALTER CONVERSION(ALTER_CONVERSION(7))CREATE FUNCTION(CREATE_FUNCTION(7))DROP CONVERSION(DROP_CONVERSION(7))
and that's the whole page, bestie π«Ά go forth and convert encodings responsibly. this has been CREATE CONVERSION(7) from the PostgreSQL 17.11 documentation, dated 2026 β catch you on the next one, mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms