{
    "content": [
        {
            "type": "text",
            "text": "# CREATE_OPERATOR_CLASS (man)\n\n## NAME\n\nCREATEOPERATORCLASS - define a new operator class\n\n## SYNOPSIS\n\nCREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE datatype\nUSING indexmethod [ FAMILY familyname ] AS\n{  OPERATOR strategynumber operatorname [ ( optype, optype ) ] [ FOR SEARCH | FOR ORDER BY sortfamilyname ]\n| FUNCTION supportnumber [ ( optype [ , optype ] ) ] functionname ( argumenttype [, ...] )\n| STORAGE storagetype\n} [, ... ]\n\n## DESCRIPTION\n\nCREATE OPERATOR CLASS creates a new operator class. An operator class defines how a\nparticular data type can be used with an index. The operator class specifies that certain\noperators will fill particular roles or \"strategies\" for this data type and this index\nmethod. The operator class also specifies the support functions to be used by the index\nmethod when the operator class is selected for an index column. All the operators and\nfunctions used by an operator class must be defined before the operator class can be created.\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_CLASS",
        "section": "",
        "mode": "man",
        "summary": "CREATEOPERATORCLASS - define a new operator class",
        "synopsis": "CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE datatype\nUSING indexmethod [ FAMILY familyname ] AS\n{  OPERATOR strategynumber operatorname [ ( optype, optype ) ] [ FOR SEARCH | FOR ORDER BY sortfamilyname ]\n| FUNCTION supportnumber [ ( optype [ , optype ] ) ] functionname ( argumenttype [, ...] )\n| STORAGE storagetype\n} [, ... ]",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "The following example command defines a GiST index operator class for the data type int4",
            "(array of int4). See the intarray module for the complete example.",
            "CREATE OPERATOR CLASS gistintops",
            "DEFAULT FOR TYPE int4 USING gist AS",
            "OPERATOR        3       &&,",
            "OPERATOR        6       = (anyarray, anyarray),",
            "OPERATOR        7       @>,",
            "OPERATOR        8       <@,",
            "OPERATOR        20      @@ (int4, queryint),",
            "FUNCTION        1       gintconsistent (internal, int4, smallint, oid, internal),",
            "FUNCTION        2       gintunion (internal, internal),",
            "FUNCTION        3       gintcompress (internal),",
            "FUNCTION        4       gintdecompress (internal),",
            "FUNCTION        5       gintpenalty (internal, internal, internal),",
            "FUNCTION        6       gintpicksplit (internal, internal),",
            "FUNCTION        7       gintsame (int4, int4, internal);"
        ],
        "see_also": [
            {
                "name": "ALTEROPERATORCLASS",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ALTEROPERATORCLASS/7/json"
            },
            {
                "name": "DROPOPERATORCLASS",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DROPOPERATORCLASS/7/json"
            },
            {
                "name": "CREATEOPERATORFAMILY",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/CREATEOPERATORFAMILY/7/json"
            },
            {
                "name": "ALTEROPERATORFAMILY",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ALTEROPERATORFAMILY/7/json"
            },
            {
                "name": "CLASS",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/CLASS/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 27,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 64,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 18,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "CREATEOPERATORCLASS - define a new operator class\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE datatype\nUSING indexmethod [ FAMILY familyname ] AS\n{  OPERATOR strategynumber operatorname [ ( optype, optype ) ] [ FOR SEARCH | FOR ORDER BY sortfamilyname ]\n| FUNCTION supportnumber [ ( optype [ , optype ] ) ] functionname ( argumenttype [, ...] )\n| STORAGE storagetype\n} [, ... ]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "CREATE OPERATOR CLASS creates a new operator class. An operator class defines how a\nparticular data type can be used with an index. The operator class specifies that certain\noperators will fill particular roles or \"strategies\" for this data type and this index\nmethod. The operator class also specifies the support functions to be used by the index\nmethod when the operator class is selected for an index column. All the operators and\nfunctions used by an operator class must be defined before the operator class can be created.\n\nIf a schema name is given then the operator class is created in the specified schema.\nOtherwise it is created in the current schema. Two operator classes in the same schema can\nhave the same name only if they are for different index methods.\n\nThe user who defines an operator class becomes its owner. Presently, the creating user must\nbe a superuser. (This restriction is made because an erroneous operator class definition\ncould confuse or even crash the server.)\n\nCREATE OPERATOR CLASS does not presently check whether the operator class definition includes\nall the operators and functions required by the index method, nor whether the operators and\nfunctions form a self-consistent set. It is the user's responsibility to define a valid\noperator class.\n\nRelated operator classes can be grouped into operator families. To add a new operator class\nto an existing family, specify the FAMILY option in CREATE OPERATOR CLASS. Without this\noption, the new class is placed into a family named the same as the new class (creating that\nfamily if it doesn't already exist).\n\nRefer to Section 38.16 for further information.\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "name\nThe name of the operator class to be created. The name can be schema-qualified.\n\nDEFAULT\nIf present, the operator class will become the default operator class for its data type.\nAt most one operator class can be the default for a specific data type and index method.\n\ndatatype\nThe column data type that this operator class is for.\n\nindexmethod\nThe name of the index method this operator class is for.\n\nfamilyname\nThe name of the existing operator family to add this operator class to. If not specified,\na family named the same as the operator class is used (creating it, if it doesn't already\nexist).\n\nstrategynumber\nThe index method's strategy number for an operator associated with the operator class.\n\noperatorname\nThe name (optionally schema-qualified) of an operator associated with the operator class.\n\noptype\nIn an OPERATOR clause, the operand data type(s) of the operator, or NONE to signify a\nprefix operator. The operand data types can be omitted in the normal case where they are\nthe same as the operator class's data type.\n\nIn a FUNCTION clause, the operand data type(s) the function is intended to support, if\ndifferent from the input data type(s) of the function (for B-tree comparison functions\nand hash functions) or the class's data type (for B-tree sort support functions, B-tree\nequal image functions, and all functions in GiST, SP-GiST, GIN and BRIN operator\nclasses). These defaults are correct, and so optype need not be specified in FUNCTION\nclauses, except for the case of a B-tree sort support function that is meant to support\ncross-data-type comparisons.\n\nsortfamilyname\nThe name (optionally schema-qualified) of an existing btree operator family that\ndescribes the sort ordering associated with an ordering operator.\n\nIf neither FOR SEARCH nor FOR ORDER BY is specified, FOR SEARCH is the default.\n\nsupportnumber\nThe index method's support function number for a function associated with the operator\nclass.\n\nfunctionname\nThe name (optionally schema-qualified) of a function that is an index method support\nfunction for the operator class.\n\nargumenttype\nThe parameter data type(s) of the function.\n\nstoragetype\nThe data type actually stored in the index. Normally this is the same as the column data\ntype, but some index methods (currently GiST, GIN, SP-GiST and BRIN) allow it to be\ndifferent. The STORAGE clause must be omitted unless the index method allows a different\ntype to be used. If the column datatype is specified as anyarray, the storagetype can\nbe declared as anyelement to indicate that the index entries are members of the element\ntype belonging to the actual array type that each particular index is created for.\n\nThe OPERATOR, FUNCTION, and STORAGE clauses can appear in any order.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "Because the index machinery does not check access permissions on functions before using them,\nincluding a function or operator in an operator class is tantamount to granting public\nexecute permission on it. This is usually not an issue for the sorts of functions that are\nuseful in an operator class.\n\nThe operators should not be defined by SQL functions. An SQL function is likely to be inlined\ninto the calling query, which will prevent the optimizer from recognizing that the query\nmatches an index.\n\nBefore PostgreSQL 8.4, the OPERATOR clause could include a RECHECK option. This is no longer\nsupported because whether an index operator is \"lossy\" is now determined on-the-fly at run\ntime. This allows efficient handling of cases where an operator might or might not be lossy.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "The following example command defines a GiST index operator class for the data type int4\n(array of int4). See the intarray module for the complete example.\n\nCREATE OPERATOR CLASS gistintops\nDEFAULT FOR TYPE int4 USING gist AS\nOPERATOR        3       &&,\nOPERATOR        6       = (anyarray, anyarray),\nOPERATOR        7       @>,\nOPERATOR        8       <@,\nOPERATOR        20      @@ (int4, queryint),\nFUNCTION        1       gintconsistent (internal, int4, smallint, oid, internal),\nFUNCTION        2       gintunion (internal, internal),\nFUNCTION        3       gintcompress (internal),\nFUNCTION        4       gintdecompress (internal),\nFUNCTION        5       gintpenalty (internal, internal, internal),\nFUNCTION        6       gintpicksplit (internal, internal),\nFUNCTION        7       gintsame (int4, int4, internal);\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "CREATE OPERATOR CLASS is a PostgreSQL extension. There is no CREATE OPERATOR CLASS statement\nin the SQL standard.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "ALTER OPERATOR CLASS (ALTEROPERATORCLASS(7)), DROP OPERATOR CLASS (DROPOPERATORCLASS(7)),\nCREATE OPERATOR FAMILY (CREATEOPERATORFAMILY(7)), ALTER OPERATOR FAMILY\n(ALTEROPERATORFAMILY(7))\n\nPostgreSQL 14.23                               2026                      CREATE OPERATOR CLASS(7)",
                "subsections": []
            }
        }
    }
}