{
    "content": [
        {
            "type": "text",
            "text": "# CREATE_OPERATOR (man)\n\n## NAME\n\nCREATEOPERATOR - define a new operator\n\n## SYNOPSIS\n\nCREATE OPERATOR name (\n{FUNCTION|PROCEDURE} = functionname\n[, LEFTARG = lefttype ] [, RIGHTARG = righttype ]\n[, COMMUTATOR = comop ] [, NEGATOR = negop ]\n[, RESTRICT = resproc ] [, JOIN = joinproc ]\n[, HASHES ] [, MERGES ]\n)\n\n## DESCRIPTION\n\nCREATE OPERATOR defines a new operator, name. The user who defines an operator becomes its\nowner. If a schema name is given then the operator is created in the specified schema.\nOtherwise it is created in the current schema.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "CREATE_OPERATOR",
        "section": "",
        "mode": "man",
        "summary": "CREATEOPERATOR - define a new operator",
        "synopsis": "CREATE OPERATOR name (\n{FUNCTION|PROCEDURE} = functionname\n[, LEFTARG = lefttype ] [, RIGHTARG = righttype ]\n[, COMMUTATOR = comop ] [, NEGATOR = negop ]\n[, RESTRICT = resproc ] [, JOIN = joinproc ]\n[, HASHES ] [, MERGES ]\n)",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "The following command defines a new operator, area-equality, for the data type box:",
            "CREATE OPERATOR === (",
            "LEFTARG = box,",
            "RIGHTARG = box,",
            "FUNCTION = areaequalfunction,",
            "COMMUTATOR = ===,",
            "NEGATOR = !==,",
            "RESTRICT = arearestrictionfunction,",
            "JOIN = areajoinfunction,",
            "HASHES, MERGES",
            ");"
        ],
        "see_also": [
            {
                "name": "ALTEROPERATOR",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ALTEROPERATOR/7/json"
            },
            {
                "name": "CREATEOPERATORCLASS",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/CREATEOPERATORCLASS/7/json"
            },
            {
                "name": "DROPOPERATOR",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DROPOPERATOR/7/json"
            },
            {
                "name": "OPERATOR",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/OPERATOR/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 42,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 39,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "CREATEOPERATOR - define a new operator\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "CREATE OPERATOR name (\n{FUNCTION|PROCEDURE} = functionname\n[, LEFTARG = lefttype ] [, RIGHTARG = righttype ]\n[, COMMUTATOR = comop ] [, NEGATOR = negop ]\n[, RESTRICT = resproc ] [, JOIN = joinproc ]\n[, HASHES ] [, MERGES ]\n)\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "CREATE OPERATOR defines a new operator, name. The user who defines an operator becomes its\nowner. If a schema name is given then the operator is created in the specified schema.\nOtherwise it is created in the current schema.\n\nThe operator name is a sequence of up to NAMEDATALEN-1 (63 by default) characters from the\nfollowing list:\n\n+ - * / < > = ~ ! @ # % ^ & | ` ?\n\nThere are a few restrictions on your choice of name:\n\n•   -- and /* cannot appear anywhere in an operator name, since they will be taken as the\nstart of a comment.\n\n•   A multicharacter operator name cannot end in + or -, unless the name also contains at\nleast one of these characters:\n\n~ ! @ # % ^ & | ` ?\n\nFor example, @- is an allowed operator name, but *- is not. This restriction allows\nPostgreSQL to parse SQL-compliant commands without requiring spaces between tokens.\n\n•   The symbol => is reserved by the SQL grammar, so it cannot be used as an operator name.\n\nThe operator != is mapped to <> on input, so these two names are always equivalent.\n\nFor binary operators, both LEFTARG and RIGHTARG must be defined. For prefix operators only\nRIGHTARG should be defined. The functionname function must have been previously defined\nusing CREATE FUNCTION and must be defined to accept the correct number of arguments (either\none or two) of the indicated types.\n\nIn the syntax of CREATE OPERATOR, the keywords FUNCTION and PROCEDURE are equivalent, but the\nreferenced function must in any case be a function, not a procedure. The use of the keyword\nPROCEDURE here is historical and deprecated.\n\nThe other clauses specify optional operator optimization clauses. Their meaning is detailed\nin Section 38.15.\n\nTo be able to create an operator, you must have USAGE privilege on the argument types and the\nreturn type, as well as EXECUTE privilege on the underlying function. If a commutator or\nnegator operator is specified, you must own these operators.\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "name\nThe name of the operator to be defined. See above for allowable characters. The name can\nbe schema-qualified, for example CREATE OPERATOR myschema.+ (...). If not, then the\noperator is created in the current schema. Two operators in the same schema can have the\nsame name if they operate on different data types. This is called overloading.\n\nfunctionname\nThe function used to implement this operator.\n\nlefttype\nThe data type of the operator's left operand, if any. This option would be omitted for a\nprefix operator.\n\nrighttype\nThe data type of the operator's right operand.\n\ncomop\nThe commutator of this operator.\n\nnegop\nThe negator of this operator.\n\nresproc\nThe restriction selectivity estimator function for this operator.\n\njoinproc\nThe join selectivity estimator function for this operator.\n\nHASHES\nIndicates this operator can support a hash join.\n\nMERGES\nIndicates this operator can support a merge join.\n\nTo give a schema-qualified operator name in comop or the other optional arguments, use the\nOPERATOR() syntax, for example:\n\nCOMMUTATOR = OPERATOR(myschema.===) ,\n",
                "subsections": []
            },
            "NOTES": {
                "content": "Refer to Section 38.14 for further information.\n\nIt is not possible to specify an operator's lexical precedence in CREATE OPERATOR, because\nthe parser's precedence behavior is hard-wired. See Section 4.1.6 for precedence details.\n\nThe obsolete options SORT1, SORT2, LTCMP, and GTCMP were formerly used to specify the names\nof sort operators associated with a merge-joinable operator. This is no longer necessary,\nsince information about associated operators is found by looking at B-tree operator families\ninstead. If one of these options is given, it is ignored except for implicitly setting MERGES\ntrue.\n\nUse DROP OPERATOR to delete user-defined operators from a database. Use ALTER OPERATOR to\nmodify operators in a database.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "The following command defines a new operator, area-equality, for the data type box:\n\nCREATE OPERATOR === (\nLEFTARG = box,\nRIGHTARG = box,\nFUNCTION = areaequalfunction,\nCOMMUTATOR = ===,\nNEGATOR = !==,\nRESTRICT = arearestrictionfunction,\nJOIN = areajoinfunction,\nHASHES, MERGES\n);\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "CREATE OPERATOR is a PostgreSQL extension. There are no provisions for user-defined operators\nin the SQL standard.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "ALTER OPERATOR (ALTEROPERATOR(7)), CREATE OPERATOR CLASS (CREATEOPERATORCLASS(7)), DROP\nOPERATOR (DROPOPERATOR(7))\n\n\n\nPostgreSQL 14.23                                2026                              CREATE OPERATOR(7)",
                "subsections": []
            }
        }
    }
}