Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/create_opclass.sgml`
8b3da04f2239ee5ff0896e1b8b0c45e68030f909ddcb57030000000100000fa9
<!--
doc/src/sgml/ref/create_opclass.sgml
PostgreSQL documentation
-->

<refentry id="sql-createopclass">
 <indexterm zone="sql-createopclass">
  <primary>CREATE OPERATOR CLASS</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>CREATE OPERATOR CLASS</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>CREATE OPERATOR CLASS</refname>
  <refpurpose>define a new operator class</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
CREATE OPERATOR CLASS <replaceable class="parameter">name</replaceable> [ DEFAULT ] FOR TYPE <replaceable class="parameter">data_type</replaceable>
  USING <replaceable class="parameter">index_method</replaceable> [ FAMILY <replaceable class="parameter">family_name</replaceable> ] AS
  {  OPERATOR <replaceable class="parameter">strategy_number</replaceable> <replaceable class="parameter">operator_name</replaceable> [ ( <replaceable class="parameter">op_type</replaceable>, <replaceable class="parameter">op_type</replaceable> ) ] [ FOR SEARCH | FOR ORDER BY <replaceable class="parameter">sort_family_name</replaceable> ]
   | FUNCTION <replaceable class="parameter">support_number</replaceable> [ ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) ] <replaceable class="parameter">function_name</replaceable> ( <replaceable class="parameter">argument_type</replaceable> [, ...] )
   | STORAGE <replaceable class="parameter">storage_type</replaceable>
  } [, ... ]
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>CREATE OPERATOR CLASS</command> creates a new operator class.
   An operator class defines how a particular data type can be used with
   an index.  The operator class specifies that certain operators will fill
   particular roles or <quote>strategies</quote> for this data type and this
   index method.  The operator class also specifies the support functions to
   be used by
   the index method when the operator class is selected for an
   index column.  All the operators and functions used by an operator
   class must be defined before the operator class can be created.
  </para>

  <para>
   If a schema name is given then the operator class is created in the
   specified schema.  Otherwise it is created in the current schema.
   Two operator classes in the same schema can have the same name only if they
   are for different index methods.
  </para>

  <para>
   The user who defines an operator class becomes its owner.  Presently,
   the creating user must be a superuser.  (This restriction is made because
   an erroneous operator class definition could confuse or even crash the
   server.)
  </para>

  <para>
   <command>CREATE OPERATOR CLASS</command> does not presently check
   whether the operator class definition includes all the operators and
   functions required by the index method, nor whether the operators and
   functions form a self-consistent set.  It is the user's
   responsibility to define a valid operator class.
  </para>

  <para>
   Related operator classes can be grouped into <firstterm>operator
   families</firstterm>.  To add a new operator class to an existing family,
   specify the <literal>FAMILY</literal> option in <command>CREATE OPERATOR
   CLASS</command>.  Without this option, the new class is placed into
   a family named the same as the new class (creating that family if
   it doesn't already exist).
  </para>

  <para>
   Refer to <xref linkend="xindex"/> for further information.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry>
    <term><replaceable class="parameter">name</replaceable></term>
    <listitem>
     <para>
      The name of the operator class to be created.  The name can be
      schema-qualified.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>DEFAULT</literal></term>
    <listitem>

Title: CREATE OPERATOR CLASS
Summary
The CREATE OPERATOR CLASS command defines a new operator class, specifying how a particular data type can be used with an index. It assigns specific roles or strategies to certain operators and designates support functions for the index method. The command requires the operators and functions to be defined beforehand and does not verify the completeness or consistency of the operator class definition. Related operator classes can be grouped into operator families.