CREATE_CONVERSION(7pg13)

πŸ“¦ version 13.23, in opensuse-leap 16.0

🌸 NAME 🌸

okay bestie, this is the CREATE CONVERSION page from the PostgreSQL 13.23 Documentation β€” you can call it the 7pg13 cut, and yes, we are getting into encoding conversions. CREATE_CONVERSION literally defines a new encoding conversion, and that's the whole vibe. slay. πŸ’…


✨ SYNOPSIS ✨

CREATE [ DEFAULT ] CONVERSION name
    FOR source_encoding TO dest_encoding FROM function_name

πŸ’– DESCRIPTION πŸ’–

So CREATE CONVERSION defines a new conversion between two character set encodings. no cap, that's the main character energy of this whole page.

Conversions marked DEFAULT can be used for automatic encoding conversion between client and server. To support that usage, two conversions β€” from encoding A to B and from encoding B to A β€” must be defined. both directions, bestie, don't forget. 🫢

To be able to create a conversion, you must have EXECUTE privilege on the function and CREATE privilege on the destination schema. permissions check, always. πŸ”‘


πŸŽ€ PARAMETERS πŸŽ€

  • DEFAULT β€” the 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. one default, okay? don't be messy.
  • name β€” 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. unique name, periodt. ✨
  • source_encoding β€” the source encoding name. what you're converting from, bestie.
  • dest_encoding β€” the destination encoding name. where it's going. πŸ¦‹
  • function_name β€” 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.

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
) RETURNS void;

like, exact signature, no improvising. 😌


πŸ’€ NOTES πŸ’€

Neither the source nor the destination encoding can be SQL_ASCII, as the server's behavior for cases involving the SQL_ASCII β€œencoding” is hard-wired. so yeah, SQL_ASCII is not invited to this party. πŸ™ˆ

bestie, use DROP CONVERSION to remove user-defined conversions. that's the cleanup crew.

The privileges required to create a conversion might be changed in a future release. so keep an eye out, okay? πŸ‘€


🌈 EXAMPLES 🌈

To create a conversion from encoding UTF8 to LATIN1 using myfunc, you literally run:

CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;

iconic. clean. does exactly what it says on the tin. πŸ’–


🧚 COMPATIBILITY 🧚

CREATE CONVERSION is a PostgreSQL extension. There is no CREATE CONVERSION statement in the SQL standard, but a CREATE TRANSLATION statement that is very similar in purpose and syntax. so like, not standard-standard, but she's still that girl. πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

go read these too, iykyk. πŸ“šβœ¨


mwah πŸ’– this page is brought to you by PostgreSQL 13.23, dated 2025 β€” now go forth and convert those encodings, bestie πŸ¦‹βœ¨

πŸ“¦ where this page comes from