CREATE_CONVERSION(7pg14)
β¨ CREATE_CONVERSION β¨
okay bestie, so this is the CREATE_CONVERSION(7) page from the PostgreSQL 14.24 docs, and it's literally about teaching your database a whole new way to translate between character set encodings π
like a little bilingual friend for your strings, no cap.
πΈ SYNOPSIS πΈ
CREATE [ DEFAULT ] CONVERSION name
FOR source_encoding TO dest_encoding FROM function_name
π DESCRIPTION π
CREATE CONVERSION defines a new conversion between two character set encodings. that's it, that's the whole vibe β you're literally registering a translator π¦
Conversions that are marked DEFAULT can be used for automatic encoding conversion between client and server. and here's the catch bestie, to support that usage, two conversions must be defined: one from encoding A to B, and one from encoding B to A. it's giving mutuals, it's giving "you follow me I follow you" π«Ά
also, to be able to create a conversion, you must have EXECUTE privilege on the function and CREATE privilege on the destination schema. permission check, slay, we love a secure queen π
π 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. one. singular. main character energy only πnameβ the name of the conversion. it can be schema-qualified, and if it's not, the conversion is defined in the current schema. the conversion name must be unique within a schema, so no stealing names, that's not cute πsource_encodingβ the source encoding name. where you're coming from π«dest_encodingβ the destination encoding name. where you're going βοΈ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 search path, bestie, it goes looking π)
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;
the return value is the number of source bytes that were successfully converted. and 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. so like, no silent failures when that boolean is false β it has to yell π
π¦ NOTES π¦
Neither the source nor the destination encoding can beSQL_ASCII, as the server's behavior for cases involving theSQL_ASCII"encoding" is hard-wired. so yeah, that one's off the table fr fr π
use DROP CONVERSION to remove user-defined conversions. cleanup era π§Ή
and a lil heads up: the privileges required to create a conversion might be changed in a future release. so don't get too attached to the current rules, they could get a glow-up π
π EXAMPLES π
to create a conversion from encoding UTF8 to LATIN1 using myfunc:
CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;
look at her go, iconic, ate and left no crumbs π₯
β COMPATIBILITY β
CREATE CONVERSION is a PostgreSQL extension. there is no CREATE CONVERSION statement in the SQL standard, but there is a CREATE TRANSLATION statement that is very similar in purpose and syntax. so like, the SQL standard has a cousin with a different name, iykyk π
π SEE ALSO π
ALTER CONVERSION(ALTER_CONVERSION(7))CREATE FUNCTION(CREATE_FUNCTION(7))DROP CONVERSION(DROP_CONVERSION(7))
okay that's the whole page bestie, go forth and convert π§ββοΈπ
sign-off szn: this lil masterpiece comes from the PostgreSQL 14.24 Documentation, dated 2026 β CREATE CONVERSION(7), and honestly? she served. periodt. π
π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-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