Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 415a9558429d583fc9b2617edd1d24a6 > files > 750

postgresql8.3-docs-8.3.8-1mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>CREATE OPERATOR</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.3.8 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="SQL Commands"
HREF="sql-commands.html"><LINK
REL="PREVIOUS"
TITLE="CREATE LANGUAGE"
HREF="sql-createlanguage.html"><LINK
REL="NEXT"
TITLE="CREATE OPERATOR CLASS"
HREF="sql-createopclass.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2009-09-04T05:13:45"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.3.8 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-createlanguage.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-createlanguage.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-createopclass.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-createopclass.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="SQL-CREATEOPERATOR"
></A
>CREATE OPERATOR</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN52881"
></A
><H2
>Name</H2
>CREATE OPERATOR&nbsp;--&nbsp;define a new operator</DIV
><A
NAME="AEN52884"
></A
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN52886"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>CREATE OPERATOR <TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
> (
    PROCEDURE = <TT
CLASS="REPLACEABLE"
><I
>funcname</I
></TT
>
    [, LEFTARG = <TT
CLASS="REPLACEABLE"
><I
>lefttype</I
></TT
> ] [, RIGHTARG = <TT
CLASS="REPLACEABLE"
><I
>righttype</I
></TT
> ]
    [, COMMUTATOR = <TT
CLASS="REPLACEABLE"
><I
>com_op</I
></TT
> ] [, NEGATOR = <TT
CLASS="REPLACEABLE"
><I
>neg_op</I
></TT
> ]
    [, RESTRICT = <TT
CLASS="REPLACEABLE"
><I
>res_proc</I
></TT
> ] [, JOIN = <TT
CLASS="REPLACEABLE"
><I
>join_proc</I
></TT
> ]
    [, HASHES ] [, MERGES ]
)</PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN52896"
></A
><H2
>Description</H2
><P
>   <TT
CLASS="COMMAND"
>CREATE OPERATOR</TT
> defines a new operator,
   <TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
>.  The user who
   defines an operator becomes its owner.  If a schema name is given
   then the operator is created in the specified schema.  Otherwise it
   is created in the current schema.
  </P
><P
>   The operator name is a sequence of up to <TT
CLASS="SYMBOL"
>NAMEDATALEN</TT
>-1
   (63 by default) characters from the following list:
<P
CLASS="LITERALLAYOUT"
>+&nbsp;-&nbsp;*&nbsp;/&nbsp;&lt;&nbsp;&gt;&nbsp;=&nbsp;~&nbsp;!&nbsp;@&nbsp;#&nbsp;%&nbsp;^&nbsp;&amp;&nbsp;|&nbsp;`&nbsp;?</P
>

   There are a few restrictions on your choice of name:
   <P
></P
></P><UL
><LI
><P
>     <TT
CLASS="LITERAL"
>--</TT
> and <TT
CLASS="LITERAL"
>/*</TT
> cannot appear anywhere in an operator name,
     since they will be taken as the start of a comment.
     </P
></LI
><LI
><P
>     A multicharacter operator name cannot end in <TT
CLASS="LITERAL"
>+</TT
> or
     <TT
CLASS="LITERAL"
>-</TT
>,
     unless the name also contains at least one of these characters:
<P
CLASS="LITERALLAYOUT"
>~&nbsp;!&nbsp;@&nbsp;#&nbsp;%&nbsp;^&nbsp;&amp;&nbsp;|&nbsp;`&nbsp;?</P
>
     For example, <TT
CLASS="LITERAL"
>@-</TT
> is an allowed operator name,
     but <TT
CLASS="LITERAL"
>*-</TT
> is not.
     This restriction allows <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> to
     parse SQL-compliant commands without requiring spaces between tokens.
     </P
></LI
></UL
><P>
  </P
><P
>   The operator <TT
CLASS="LITERAL"
>!=</TT
> is mapped to
   <TT
CLASS="LITERAL"
>&lt;&gt;</TT
> on input, so these two names are always
   equivalent.
  </P
><P
>   At least one of <TT
CLASS="LITERAL"
>LEFTARG</TT
> and <TT
CLASS="LITERAL"
>RIGHTARG</TT
> must be defined.  For
   binary operators, both must be defined. For right  unary
   operators, only <TT
CLASS="LITERAL"
>LEFTARG</TT
> should be defined, while for left
   unary operators only <TT
CLASS="LITERAL"
>RIGHTARG</TT
> should be defined.
  </P
><P
>   The <TT
CLASS="REPLACEABLE"
><I
>funcname</I
></TT
>
   procedure must have been previously defined using <TT
CLASS="COMMAND"
>CREATE
   FUNCTION</TT
> and must be defined to accept the correct number
   of arguments (either one or two) of the indicated types.
  </P
><P
>   The other clauses specify optional operator optimization clauses.
   Their meaning is detailed in <A
HREF="xoper-optimization.html"
>Section 34.13</A
>.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN52930"
></A
><H2
>Parameters</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
></DT
><DD
><P
>        The name of the operator to be defined. See above for allowable
        characters.  The name can be schema-qualified, for example
        <TT
CLASS="LITERAL"
>CREATE OPERATOR myschema.+ (...)</TT
>.  If not, then
        the operator is created in the current schema.  Two operators
        in the same schema can have the same name if they operate on
        different data types.  This is called
        <I
CLASS="FIRSTTERM"
>overloading</I
>.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>funcname</I
></TT
></DT
><DD
><P
>        The function used to implement this operator.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>lefttype</I
></TT
></DT
><DD
><P
>        The data type of the operator's left operand, if any.
        This option would be omitted for a left-unary operator.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>righttype</I
></TT
></DT
><DD
><P
>        The data type of the operator's right operand, if any.
        This option would be omitted for a right-unary operator.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>com_op</I
></TT
></DT
><DD
><P
>        The commutator of this operator.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>neg_op</I
></TT
></DT
><DD
><P
>        The negator of this operator.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>res_proc</I
></TT
></DT
><DD
><P
>        The restriction selectivity estimator function for this operator.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>join_proc</I
></TT
></DT
><DD
><P
>        The join selectivity estimator function for this operator.
       </P
></DD
><DT
><TT
CLASS="LITERAL"
>HASHES</TT
></DT
><DD
><P
>       Indicates this operator can support a hash join.
       </P
></DD
><DT
><TT
CLASS="LITERAL"
>MERGES</TT
></DT
><DD
><P
>       Indicates this operator can support a merge join.
       </P
></DD
></DL
></DIV
><P
>   To give a schema-qualified operator name in <TT
CLASS="REPLACEABLE"
><I
>com_op</I
></TT
> or the other optional
   arguments, use the <TT
CLASS="LITERAL"
>OPERATOR()</TT
> syntax, for example:
</P><PRE
CLASS="PROGRAMLISTING"
>COMMUTATOR = OPERATOR(myschema.===) ,</PRE
><P>  
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN52989"
></A
><H2
>Notes</H2
><P
>   Refer to <A
HREF="xoper.html"
>Section 34.12</A
> for further information.
  </P
><P
>   The obsolete options <TT
CLASS="LITERAL"
>SORT1</TT
>, <TT
CLASS="LITERAL"
>SORT2</TT
>,
   <TT
CLASS="LITERAL"
>LTCMP</TT
>, and <TT
CLASS="LITERAL"
>GTCMP</TT
> were formerly used to
   specify the names of sort operators associated with a merge-joinable
   operator.  This is no longer necessary, since information about
   associated operators is found by looking at B-tree operator families
   instead.  If one of these options is given, it is ignored except
   for implicitly setting <TT
CLASS="LITERAL"
>MERGES</TT
> true.
  </P
><P
>   Use <A
HREF="sql-dropoperator.html"
><I
>DROP OPERATOR</I
></A
> to delete user-defined operators
   from a database.  Use <A
HREF="sql-alteroperator.html"
><I
>ALTER OPERATOR</I
></A
> to modify operators in a
   database.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN53002"
></A
><H2
>Examples</H2
><P
>   The following command defines a new operator, area-equality, for
   the data type <TT
CLASS="TYPE"
>box</TT
>:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE OPERATOR === (
    LEFTARG = box,
    RIGHTARG = box,
    PROCEDURE = area_equal_procedure,
    COMMUTATOR = ===,
    NEGATOR = !==,
    RESTRICT = area_restriction_procedure,
    JOIN = area_join_procedure,
    HASHES, MERGES
);</PRE
><P>  
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN53007"
></A
><H2
>Compatibility</H2
><P
>   <TT
CLASS="COMMAND"
>CREATE OPERATOR</TT
> is a
   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> extension.  There are no
   provisions for user-defined operators in the SQL standard.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN53012"
></A
><H2
>See Also</H2
><A
HREF="sql-alteroperator.html"
><I
>ALTER OPERATOR</I
></A
>, <A
HREF="sql-createopclass.html"
><I
>CREATE OPERATOR CLASS</I
></A
>, <A
HREF="sql-dropoperator.html"
><I
>DROP OPERATOR</I
></A
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-createlanguage.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-createopclass.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>CREATE LANGUAGE</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>CREATE OPERATOR CLASS</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>