~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/html/sql-createopclass.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>CREATE OPERATOR CLASS</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REV="MADE"
 
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
 
11
REL="HOME"
 
12
TITLE="PostgreSQL 9.1beta1 Documentation"
 
13
HREF="index.html"><LINK
 
14
REL="UP"
 
15
TITLE="SQL Commands"
 
16
HREF="sql-commands.html"><LINK
 
17
REL="PREVIOUS"
 
18
TITLE="CREATE OPERATOR"
 
19
HREF="sql-createoperator.html"><LINK
 
20
REL="NEXT"
 
21
TITLE="CREATE OPERATOR FAMILY"
 
22
HREF="sql-createopfamily.html"><LINK
 
23
REL="STYLESHEET"
 
24
TYPE="text/css"
 
25
HREF="stylesheet.css"><META
 
26
HTTP-EQUIV="Content-Type"
 
27
CONTENT="text/html; charset=ISO-8859-1"><META
 
28
NAME="creation"
 
29
CONTENT="2011-04-27T21:20:33"></HEAD
 
30
><BODY
 
31
CLASS="REFENTRY"
 
32
><DIV
 
33
CLASS="NAVHEADER"
 
34
><TABLE
 
35
SUMMARY="Header navigation table"
 
36
WIDTH="100%"
 
37
BORDER="0"
 
38
CELLPADDING="0"
 
39
CELLSPACING="0"
 
40
><TR
 
41
><TH
 
42
COLSPAN="5"
 
43
ALIGN="center"
 
44
VALIGN="bottom"
 
45
><A
 
46
HREF="index.html"
 
47
>PostgreSQL 9.1beta1 Documentation</A
 
48
></TH
 
49
></TR
 
50
><TR
 
51
><TD
 
52
WIDTH="10%"
 
53
ALIGN="left"
 
54
VALIGN="top"
 
55
><A
 
56
TITLE="CREATE OPERATOR"
 
57
HREF="sql-createoperator.html"
 
58
ACCESSKEY="P"
 
59
>Prev</A
 
60
></TD
 
61
><TD
 
62
WIDTH="10%"
 
63
ALIGN="left"
 
64
VALIGN="top"
 
65
><A
 
66
TITLE="CREATE OPERATOR"
 
67
HREF="sql-createoperator.html"
 
68
>Fast Backward</A
 
69
></TD
 
70
><TD
 
71
WIDTH="60%"
 
72
ALIGN="center"
 
73
VALIGN="bottom"
 
74
></TD
 
75
><TD
 
76
WIDTH="10%"
 
77
ALIGN="right"
 
78
VALIGN="top"
 
79
><A
 
80
TITLE="CREATE OPERATOR FAMILY"
 
81
HREF="sql-createopfamily.html"
 
82
>Fast Forward</A
 
83
></TD
 
84
><TD
 
85
WIDTH="10%"
 
86
ALIGN="right"
 
87
VALIGN="top"
 
88
><A
 
89
TITLE="CREATE OPERATOR FAMILY"
 
90
HREF="sql-createopfamily.html"
 
91
ACCESSKEY="N"
 
92
>Next</A
 
93
></TD
 
94
></TR
 
95
></TABLE
 
96
><HR
 
97
ALIGN="LEFT"
 
98
WIDTH="100%"></DIV
 
99
><H1
 
100
><A
 
101
NAME="SQL-CREATEOPCLASS"
 
102
></A
 
103
>CREATE OPERATOR CLASS</H1
 
104
><DIV
 
105
CLASS="REFNAMEDIV"
 
106
><A
 
107
NAME="AEN66164"
 
108
></A
 
109
><H2
 
110
>Name</H2
 
111
>CREATE OPERATOR CLASS&nbsp;--&nbsp;define a new operator class</DIV
 
112
><DIV
 
113
CLASS="REFSYNOPSISDIV"
 
114
><A
 
115
NAME="AEN66169"
 
116
></A
 
117
><H2
 
118
>Synopsis</H2
 
119
><PRE
 
120
CLASS="SYNOPSIS"
 
121
>CREATE OPERATOR CLASS <TT
 
122
CLASS="REPLACEABLE"
 
123
><I
 
124
>name</I
 
125
></TT
 
126
> [ DEFAULT ] FOR TYPE <TT
 
127
CLASS="REPLACEABLE"
 
128
><I
 
129
>data_type</I
 
130
></TT
 
131
>
 
132
  USING <TT
 
133
CLASS="REPLACEABLE"
 
134
><I
 
135
>index_method</I
 
136
></TT
 
137
> [ FAMILY <TT
 
138
CLASS="REPLACEABLE"
 
139
><I
 
140
>family_name</I
 
141
></TT
 
142
> ] AS
 
143
  {  OPERATOR <TT
 
144
CLASS="REPLACEABLE"
 
145
><I
 
146
>strategy_number</I
 
147
></TT
 
148
> <TT
 
149
CLASS="REPLACEABLE"
 
150
><I
 
151
>operator_name</I
 
152
></TT
 
153
> [ ( <TT
 
154
CLASS="REPLACEABLE"
 
155
><I
 
156
>op_type</I
 
157
></TT
 
158
>, <TT
 
159
CLASS="REPLACEABLE"
 
160
><I
 
161
>op_type</I
 
162
></TT
 
163
> ) ] [ FOR SEARCH | FOR ORDER BY <TT
 
164
CLASS="REPLACEABLE"
 
165
><I
 
166
>sort_family_name</I
 
167
></TT
 
168
> ]
 
169
   | FUNCTION <TT
 
170
CLASS="REPLACEABLE"
 
171
><I
 
172
>support_number</I
 
173
></TT
 
174
> [ ( <TT
 
175
CLASS="REPLACEABLE"
 
176
><I
 
177
>op_type</I
 
178
></TT
 
179
> [ , <TT
 
180
CLASS="REPLACEABLE"
 
181
><I
 
182
>op_type</I
 
183
></TT
 
184
> ] ) ] <TT
 
185
CLASS="REPLACEABLE"
 
186
><I
 
187
>function_name</I
 
188
></TT
 
189
> ( <TT
 
190
CLASS="REPLACEABLE"
 
191
><I
 
192
>argument_type</I
 
193
></TT
 
194
> [, ...] )
 
195
   | STORAGE <TT
 
196
CLASS="REPLACEABLE"
 
197
><I
 
198
>storage_type</I
 
199
></TT
 
200
>
 
201
  } [, ... ]</PRE
 
202
></DIV
 
203
><DIV
 
204
CLASS="REFSECT1"
 
205
><A
 
206
NAME="AEN66186"
 
207
></A
 
208
><H2
 
209
>Description</H2
 
210
><P
 
211
>   <TT
 
212
CLASS="COMMAND"
 
213
>CREATE OPERATOR CLASS</TT
 
214
> creates a new operator class.
 
215
   An operator class defines how a particular data type can be used with
 
216
   an index.  The operator class specifies that certain operators will fill
 
217
   particular roles or <SPAN
 
218
CLASS="QUOTE"
 
219
>"strategies"</SPAN
 
220
> for this data type and this
 
221
   index method.  The operator class also specifies the support procedures to
 
222
   be used by
 
223
   the index method when the operator class is selected for an
 
224
   index column.  All the operators and functions used by an operator
 
225
   class must be defined before the operator class can be created.
 
226
  </P
 
227
><P
 
228
>   If a schema name is given then the operator class is created in the
 
229
   specified schema.  Otherwise it is created in the current schema.
 
230
   Two operator classes in the same schema can have the same name only if they
 
231
   are for different index methods.
 
232
  </P
 
233
><P
 
234
>   The user who defines an operator class becomes its owner.  Presently,
 
235
   the creating user must be a superuser.  (This restriction is made because
 
236
   an erroneous operator class definition could confuse or even crash the
 
237
   server.)
 
238
  </P
 
239
><P
 
240
>   <TT
 
241
CLASS="COMMAND"
 
242
>CREATE OPERATOR CLASS</TT
 
243
> does not presently check
 
244
   whether the operator class definition includes all the operators and
 
245
   functions required by the index method, nor whether the operators and
 
246
   functions form a self-consistent set.  It is the user's
 
247
   responsibility to define a valid operator class.
 
248
  </P
 
249
><P
 
250
>   Related operator classes can be grouped into <I
 
251
CLASS="FIRSTTERM"
 
252
>operator
 
253
   families</I
 
254
>.  To add a new operator class to an existing family,
 
255
   specify the <TT
 
256
CLASS="LITERAL"
 
257
>FAMILY</TT
 
258
> option in <TT
 
259
CLASS="COMMAND"
 
260
>CREATE OPERATOR
 
261
   CLASS</TT
 
262
>.  Without this option, the new class is placed into
 
263
   a family named the same as the new class (creating that family if
 
264
   it doesn't already exist).
 
265
  </P
 
266
><P
 
267
>   Refer to <A
 
268
HREF="xindex.html"
 
269
>Section 35.14</A
 
270
> for further information.
 
271
  </P
 
272
></DIV
 
273
><DIV
 
274
CLASS="REFSECT1"
 
275
><A
 
276
NAME="AEN66201"
 
277
></A
 
278
><H2
 
279
>Parameters</H2
 
280
><P
 
281
></P
 
282
><DIV
 
283
CLASS="VARIABLELIST"
 
284
><DL
 
285
><DT
 
286
><TT
 
287
CLASS="REPLACEABLE"
 
288
><I
 
289
>name</I
 
290
></TT
 
291
></DT
 
292
><DD
 
293
><P
 
294
>      The name of the operator class to be created.  The name can be
 
295
      schema-qualified.
 
296
     </P
 
297
></DD
 
298
><DT
 
299
><TT
 
300
CLASS="LITERAL"
 
301
>DEFAULT</TT
 
302
></DT
 
303
><DD
 
304
><P
 
305
>      If present, the operator class will become the default
 
306
      operator class for its data type.  At most one operator class
 
307
      can be the default for a specific data type and index method.
 
308
     </P
 
309
></DD
 
310
><DT
 
311
><TT
 
312
CLASS="REPLACEABLE"
 
313
><I
 
314
>data_type</I
 
315
></TT
 
316
></DT
 
317
><DD
 
318
><P
 
319
>      The column data type that this operator class is for.
 
320
     </P
 
321
></DD
 
322
><DT
 
323
><TT
 
324
CLASS="REPLACEABLE"
 
325
><I
 
326
>index_method</I
 
327
></TT
 
328
></DT
 
329
><DD
 
330
><P
 
331
>      The name of the index method this operator class is for.
 
332
     </P
 
333
></DD
 
334
><DT
 
335
><TT
 
336
CLASS="REPLACEABLE"
 
337
><I
 
338
>family_name</I
 
339
></TT
 
340
></DT
 
341
><DD
 
342
><P
 
343
>      The name of the existing operator family to add this operator class to.
 
344
      If not specified, a family named the same as the operator class is
 
345
      used (creating it, if it doesn't already exist).
 
346
     </P
 
347
></DD
 
348
><DT
 
349
><TT
 
350
CLASS="REPLACEABLE"
 
351
><I
 
352
>strategy_number</I
 
353
></TT
 
354
></DT
 
355
><DD
 
356
><P
 
357
>      The index method's strategy number for an operator
 
358
      associated with the operator class.
 
359
     </P
 
360
></DD
 
361
><DT
 
362
><TT
 
363
CLASS="REPLACEABLE"
 
364
><I
 
365
>operator_name</I
 
366
></TT
 
367
></DT
 
368
><DD
 
369
><P
 
370
>      The name (optionally schema-qualified) of an operator associated
 
371
      with the operator class.
 
372
     </P
 
373
></DD
 
374
><DT
 
375
><TT
 
376
CLASS="REPLACEABLE"
 
377
><I
 
378
>op_type</I
 
379
></TT
 
380
></DT
 
381
><DD
 
382
><P
 
383
>      In an <TT
 
384
CLASS="LITERAL"
 
385
>OPERATOR</TT
 
386
> clause,
 
387
      the operand data type(s) of the operator, or <TT
 
388
CLASS="LITERAL"
 
389
>NONE</TT
 
390
> to
 
391
      signify a left-unary or right-unary operator.  The operand data
 
392
      types can be omitted in the normal case where they are the same
 
393
      as the operator class's data type.
 
394
     </P
 
395
><P
 
396
>      In a <TT
 
397
CLASS="LITERAL"
 
398
>FUNCTION</TT
 
399
> clause, the operand data type(s) the
 
400
      function is intended to support, if different from
 
401
      the input data type(s) of the function (for B-tree and hash indexes)
 
402
      or the class's data type (for GIN and GiST indexes).  These defaults
 
403
      are always correct, so there is no point in specifying <TT
 
404
CLASS="REPLACEABLE"
 
405
><I
 
406
>op_type</I
 
407
></TT
 
408
> in a <TT
 
409
CLASS="LITERAL"
 
410
>FUNCTION</TT
 
411
> clause
 
412
      in <TT
 
413
CLASS="COMMAND"
 
414
>CREATE OPERATOR CLASS</TT
 
415
>, but the option is provided
 
416
      for consistency with the comparable syntax in
 
417
      <TT
 
418
CLASS="COMMAND"
 
419
>ALTER OPERATOR FAMILY</TT
 
420
>.
 
421
     </P
 
422
></DD
 
423
><DT
 
424
><TT
 
425
CLASS="REPLACEABLE"
 
426
><I
 
427
>sort_family_name</I
 
428
></TT
 
429
></DT
 
430
><DD
 
431
><P
 
432
>      The name (optionally schema-qualified) of an existing btree operator
 
433
      family that describes the sort ordering associated with an ordering
 
434
      operator.
 
435
     </P
 
436
><P
 
437
>      If neither <TT
 
438
CLASS="LITERAL"
 
439
>FOR SEARCH</TT
 
440
> nor <TT
 
441
CLASS="LITERAL"
 
442
>FOR ORDER BY</TT
 
443
> is
 
444
      specified, <TT
 
445
CLASS="LITERAL"
 
446
>FOR SEARCH</TT
 
447
> is the default.
 
448
     </P
 
449
></DD
 
450
><DT
 
451
><TT
 
452
CLASS="REPLACEABLE"
 
453
><I
 
454
>support_number</I
 
455
></TT
 
456
></DT
 
457
><DD
 
458
><P
 
459
>      The index method's support procedure number for a
 
460
      function associated with the operator class.
 
461
     </P
 
462
></DD
 
463
><DT
 
464
><TT
 
465
CLASS="REPLACEABLE"
 
466
><I
 
467
>function_name</I
 
468
></TT
 
469
></DT
 
470
><DD
 
471
><P
 
472
>      The name (optionally schema-qualified) of a function that is an
 
473
      index method support procedure for the operator class.
 
474
     </P
 
475
></DD
 
476
><DT
 
477
><TT
 
478
CLASS="REPLACEABLE"
 
479
><I
 
480
>argument_type</I
 
481
></TT
 
482
></DT
 
483
><DD
 
484
><P
 
485
>      The parameter data type(s) of the function.
 
486
     </P
 
487
></DD
 
488
><DT
 
489
><TT
 
490
CLASS="REPLACEABLE"
 
491
><I
 
492
>storage_type</I
 
493
></TT
 
494
></DT
 
495
><DD
 
496
><P
 
497
>      The data type actually stored in the index.  Normally this is
 
498
      the same as the column data type, but some index methods
 
499
      (currently GIN and GiST) allow it to be different.  The
 
500
      <TT
 
501
CLASS="LITERAL"
 
502
>STORAGE</TT
 
503
> clause must be omitted unless the index
 
504
      method allows a different type to be used.
 
505
     </P
 
506
></DD
 
507
></DL
 
508
></DIV
 
509
><P
 
510
>   The <TT
 
511
CLASS="LITERAL"
 
512
>OPERATOR</TT
 
513
>, <TT
 
514
CLASS="LITERAL"
 
515
>FUNCTION</TT
 
516
>, and <TT
 
517
CLASS="LITERAL"
 
518
>STORAGE</TT
 
519
>
 
520
   clauses can appear in any order.
 
521
  </P
 
522
></DIV
 
523
><DIV
 
524
CLASS="REFSECT1"
 
525
><A
 
526
NAME="AEN66286"
 
527
></A
 
528
><H2
 
529
>Notes</H2
 
530
><P
 
531
>   Because the index machinery does not check access permissions on functions
 
532
   before using them, including a function or operator in an operator class
 
533
   is tantamount to granting public execute permission on it.  This is usually
 
534
   not an issue for the sorts of functions that are useful in an operator
 
535
   class.
 
536
  </P
 
537
><P
 
538
>   The operators should not be defined by SQL functions.  A SQL function
 
539
   is likely to be inlined into the calling query, which will prevent
 
540
   the optimizer from recognizing that the query matches an index.
 
541
  </P
 
542
><P
 
543
>   Before <SPAN
 
544
CLASS="PRODUCTNAME"
 
545
>PostgreSQL</SPAN
 
546
> 8.4, the <TT
 
547
CLASS="LITERAL"
 
548
>OPERATOR</TT
 
549
>
 
550
   clause could include a <TT
 
551
CLASS="LITERAL"
 
552
>RECHECK</TT
 
553
> option.  This is no longer
 
554
   supported because whether an index operator is <SPAN
 
555
CLASS="QUOTE"
 
556
>"lossy"</SPAN
 
557
> is now
 
558
   determined on-the-fly at run time.  This allows efficient handling of
 
559
   cases where an operator might or might not be lossy.
 
560
  </P
 
561
></DIV
 
562
><DIV
 
563
CLASS="REFSECT1"
 
564
><A
 
565
NAME="AEN66295"
 
566
></A
 
567
><H2
 
568
>Examples</H2
 
569
><P
 
570
>   The following example command defines a GiST index operator class
 
571
   for the data type <TT
 
572
CLASS="LITERAL"
 
573
>_int4</TT
 
574
> (array of <TT
 
575
CLASS="TYPE"
 
576
>int4</TT
 
577
>).  See the
 
578
   <A
 
579
HREF="intarray.html"
 
580
>Section F.18</A
 
581
> module for the complete example.
 
582
  </P
 
583
><PRE
 
584
CLASS="PROGRAMLISTING"
 
585
>CREATE OPERATOR CLASS gist__int_ops
 
586
    DEFAULT FOR TYPE _int4 USING gist AS
 
587
        OPERATOR        3       &amp;&amp;,
 
588
        OPERATOR        6       = (anyarray, anyarray),
 
589
        OPERATOR        7       @&gt;,
 
590
        OPERATOR        8       &lt;@,
 
591
        OPERATOR        20      @@ (_int4, query_int),
 
592
        FUNCTION        1       g_int_consistent (internal, _int4, int, oid, internal),
 
593
        FUNCTION        2       g_int_union (internal, internal),
 
594
        FUNCTION        3       g_int_compress (internal),
 
595
        FUNCTION        4       g_int_decompress (internal),
 
596
        FUNCTION        5       g_int_penalty (internal, internal, internal),
 
597
        FUNCTION        6       g_int_picksplit (internal, internal),
 
598
        FUNCTION        7       g_int_same (_int4, _int4, internal);</PRE
 
599
></DIV
 
600
><DIV
 
601
CLASS="REFSECT1"
 
602
><A
 
603
NAME="AEN66302"
 
604
></A
 
605
><H2
 
606
>Compatibility</H2
 
607
><P
 
608
>   <TT
 
609
CLASS="COMMAND"
 
610
>CREATE OPERATOR CLASS</TT
 
611
> is a
 
612
   <SPAN
 
613
CLASS="PRODUCTNAME"
 
614
>PostgreSQL</SPAN
 
615
> extension.  There is no
 
616
   <TT
 
617
CLASS="COMMAND"
 
618
>CREATE OPERATOR CLASS</TT
 
619
> statement in the SQL
 
620
   standard.
 
621
  </P
 
622
></DIV
 
623
><DIV
 
624
CLASS="REFSECT1"
 
625
><A
 
626
NAME="AEN66308"
 
627
></A
 
628
><H2
 
629
>See Also</H2
 
630
><A
 
631
HREF="sql-alteropclass.html"
 
632
>ALTER OPERATOR CLASS</A
 
633
>, <A
 
634
HREF="sql-dropopclass.html"
 
635
>DROP OPERATOR CLASS</A
 
636
>, <A
 
637
HREF="sql-createopfamily.html"
 
638
>CREATE OPERATOR FAMILY</A
 
639
>, <A
 
640
HREF="sql-alteropfamily.html"
 
641
>ALTER OPERATOR FAMILY</A
 
642
></DIV
 
643
><DIV
 
644
CLASS="NAVFOOTER"
 
645
><HR
 
646
ALIGN="LEFT"
 
647
WIDTH="100%"><TABLE
 
648
SUMMARY="Footer navigation table"
 
649
WIDTH="100%"
 
650
BORDER="0"
 
651
CELLPADDING="0"
 
652
CELLSPACING="0"
 
653
><TR
 
654
><TD
 
655
WIDTH="33%"
 
656
ALIGN="left"
 
657
VALIGN="top"
 
658
><A
 
659
HREF="sql-createoperator.html"
 
660
ACCESSKEY="P"
 
661
>Prev</A
 
662
></TD
 
663
><TD
 
664
WIDTH="34%"
 
665
ALIGN="center"
 
666
VALIGN="top"
 
667
><A
 
668
HREF="index.html"
 
669
ACCESSKEY="H"
 
670
>Home</A
 
671
></TD
 
672
><TD
 
673
WIDTH="33%"
 
674
ALIGN="right"
 
675
VALIGN="top"
 
676
><A
 
677
HREF="sql-createopfamily.html"
 
678
ACCESSKEY="N"
 
679
>Next</A
 
680
></TD
 
681
></TR
 
682
><TR
 
683
><TD
 
684
WIDTH="33%"
 
685
ALIGN="left"
 
686
VALIGN="top"
 
687
>CREATE OPERATOR</TD
 
688
><TD
 
689
WIDTH="34%"
 
690
ALIGN="center"
 
691
VALIGN="top"
 
692
><A
 
693
HREF="sql-commands.html"
 
694
ACCESSKEY="U"
 
695
>Up</A
 
696
></TD
 
697
><TD
 
698
WIDTH="33%"
 
699
ALIGN="right"
 
700
VALIGN="top"
 
701
>CREATE OPERATOR FAMILY</TD
 
702
></TR
 
703
></TABLE
 
704
></DIV
 
705
></BODY
 
706
></HTML
 
707
>
 
 
b'\\ No newline at end of file'