{
    "mode": "man",
    "parameter": "CREATE_TRANSFORM",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/CREATE_TRANSFORM/7/json",
    "generated": "2026-07-05T09:34:35Z",
    "synopsis": "CREATE [ OR REPLACE ] TRANSFORM FOR typename LANGUAGE langname (\nFROM SQL WITH FUNCTION fromsqlfunctionname [ (argumenttype [, ...]) ],\nTO SQL WITH FUNCTION tosqlfunctionname [ (argumenttype [, ...]) ]\n);",
    "sections": {
        "NAME": {
            "content": "CREATETRANSFORM - define a new transform\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "CREATE [ OR REPLACE ] TRANSFORM FOR typename LANGUAGE langname (\nFROM SQL WITH FUNCTION fromsqlfunctionname [ (argumenttype [, ...]) ],\nTO SQL WITH FUNCTION tosqlfunctionname [ (argumenttype [, ...]) ]\n);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "CREATE TRANSFORM defines a new transform.  CREATE OR REPLACE TRANSFORM will either create a\nnew transform, or replace an existing definition.\n\nA transform specifies how to adapt a data type to a procedural language. For example, when\nwriting a function in PL/Python using the hstore type, PL/Python has no prior knowledge how\nto present hstore values in the Python environment. Language implementations usually default\nto using the text representation, but that is inconvenient when, for example, an associative\narray or a list would be more appropriate.\n\nA transform specifies two functions:\n\n•   A “from SQL” function that converts the type from the SQL environment to the language.\nThis function will be invoked on the arguments of a function written in the language.\n\n•   A “to SQL” function that converts the type from the language to the SQL environment. This\nfunction will be invoked on the return value of a function written in the language.\n\nIt is not necessary to provide both of these functions. If one is not specified, the\nlanguage-specific default behavior will be used if necessary. (To prevent a transformation in\na certain direction from happening at all, you could also write a transform function that\nalways errors out.)\n\nTo be able to create a transform, you must own and have USAGE privilege on the type, have\nUSAGE privilege on the language, and own and have EXECUTE privilege on the from-SQL and\nto-SQL functions, if specified.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "typename\nThe name of the data type of the transform.\n\nlangname\nThe name of the language of the transform.\n\nfromsqlfunctionname[(argumenttype [, ...])]\nThe name of the function for converting the type from the SQL environment to the\nlanguage. It must take one argument of type internal and return type internal. The actual\nargument will be of the type for the transform, and the function should be coded as if it\nwere. (But it is not allowed to declare an SQL-level function returning internal without\nat least one argument of type internal.) The actual return value will be something\nspecific to the language implementation. If no argument list is specified, the function\nname must be unique in its schema.\n\ntosqlfunctionname[(argumenttype [, ...])]\nThe name of the function for converting the type from the language to the SQL\nenvironment. It must take one argument of type internal and return the type that is the\ntype for the transform. The actual argument value will be something specific to the\nlanguage implementation. If no argument list is specified, the function name must be\nunique in its schema.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Use DROP TRANSFORM to remove transforms.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To create a transform for type hstore and language plpythonu, first set up the type and the\nlanguage:\n\nCREATE TYPE hstore ...;\n\nCREATE EXTENSION plpythonu;\n\nThen create the necessary functions:\n\nCREATE FUNCTION hstoretoplpython(val internal) RETURNS internal\nLANGUAGE C STRICT IMMUTABLE\nAS ...;\n\nCREATE FUNCTION plpythontohstore(val internal) RETURNS hstore\nLANGUAGE C STRICT IMMUTABLE\nAS ...;\n\nAnd finally create the transform to connect them all together:\n\nCREATE TRANSFORM FOR hstore LANGUAGE plpythonu (\nFROM SQL WITH FUNCTION hstoretoplpython(internal),\nTO SQL WITH FUNCTION plpythontohstore(internal)\n);\n\nIn practice, these commands would be wrapped up in an extension.\n\nThe contrib section contains a number of extensions that provide transforms, which can serve\nas real-world examples.\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "This form of CREATE TRANSFORM is a PostgreSQL extension. There is a CREATE TRANSFORM command\nin the SQL standard, but it is for adapting data types to client languages. That usage is not\nsupported by PostgreSQL.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "CREATE FUNCTION (CREATEFUNCTION(7)), CREATE LANGUAGE (CREATELANGUAGE(7)), CREATE TYPE\n(CREATETYPE(7)), DROP TRANSFORM (DROPTRANSFORM(7))\n\n\n\nPostgreSQL 14.23                                2026                             CREATE TRANSFORM(7)",
            "subsections": []
        }
    },
    "summary": "CREATETRANSFORM - define a new transform",
    "flags": [],
    "examples": [
        "To create a transform for type hstore and language plpythonu, first set up the type and the",
        "language:",
        "CREATE TYPE hstore ...;",
        "CREATE EXTENSION plpythonu;",
        "Then create the necessary functions:",
        "CREATE FUNCTION hstoretoplpython(val internal) RETURNS internal",
        "LANGUAGE C STRICT IMMUTABLE",
        "AS ...;",
        "CREATE FUNCTION plpythontohstore(val internal) RETURNS hstore",
        "LANGUAGE C STRICT IMMUTABLE",
        "AS ...;",
        "And finally create the transform to connect them all together:",
        "CREATE TRANSFORM FOR hstore LANGUAGE plpythonu (",
        "FROM SQL WITH FUNCTION hstoretoplpython(internal),",
        "TO SQL WITH FUNCTION plpythontohstore(internal)",
        ");",
        "In practice, these commands would be wrapped up in an extension.",
        "The contrib section contains a number of extensions that provide transforms, which can serve",
        "as real-world examples."
    ],
    "see_also": [
        {
            "name": "CREATEFUNCTION",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATEFUNCTION/7/json"
        },
        {
            "name": "CREATELANGUAGE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATELANGUAGE/7/json"
        },
        {
            "name": "CREATETYPE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATETYPE/7/json"
        },
        {
            "name": "DROPTRANSFORM",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPTRANSFORM/7/json"
        },
        {
            "name": "TRANSFORM",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/TRANSFORM/7/json"
        }
    ]
}