1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
12
TITLE="PostgreSQL 9.3beta1 Documentation"
13
HREF="index.html"><LINK
15
TITLE="Additional Supplied Modules"
16
HREF="contrib.html"><LINK
19
HREF="citext.html"><LINK
22
HREF="dblink.html"><LINK
25
HREF="stylesheet.css"><META
26
HTTP-EQUIV="Content-Type"
27
CONTENT="text/html; charset=ISO-8859-1"><META
29
CONTENT="2013-05-06T21:00:50"></HEAD
35
SUMMARY="Header navigation table"
47
>PostgreSQL 9.3beta1 Documentation</A
74
>Appendix F. Additional Supplied Modules</TD
99
> This module implements a data type <TT
103
representing multidimensional cubes.
115
HREF="cube.html#CUBE-REPR-TABLE"
117
> shows the valid external
118
representations for the <TT
133
floating-point numbers.
138
NAME="CUBE-REPR-TABLE"
142
>Table F-1. Cube External Representations</B
160
>A one-dimensional point
161
(or, zero-length one-dimensional interval)
200
>A point in n-dimensional space, represented internally as a
245
>A one-dimensional interval starting at <TT
256
order does not matter
305
>An n-dimensional cube represented by a pair of its diagonally
342
> It does not matter which order the opposite corners of a cube are
347
automatically swap values if needed to create a uniform
350
>"lower left — upper right"</SPAN
351
> internal representation.
354
> White space is ignored, so <TT
393
> Values are stored internally as 64-bit floating point numbers. This means
394
that numbers with more than about 16 significant digits will be truncated.
409
> module includes a GiST index operator class for
414
The operators supported by the GiST operator class are shown in <A
415
HREF="cube.html#CUBE-GIST-OPERATORS"
422
NAME="CUBE-GIST-OPERATORS"
426
>Table F-2. Cube GiST Operators</B
447
>The cubes a and b are identical.</TD
456
>The cubes a and b overlap.</TD
465
>The cube a contains the cube b.</TD
474
>The cube a is contained in the cube b.</TD
480
> (Before PostgreSQL 8.2, the containment operators <TT
487
respectively called <TT
493
>. These names are still available, but are
494
deprecated and will eventually be retired. Notice that the old names
495
are reversed from the convention formerly followed by the core geometric
499
> The standard B-tree operators are also provided, for example
502
CLASS="INFORMALTABLE"
524
>[a, b] < [c, d]</TT
533
>[a, b] > [c, d]</TT
545
These operators do not make a lot of sense for any practical
546
purpose but sorting. These operators first compare (a) to (c),
547
and if these are equal, compare (b) to (d). That results in
548
reasonably good sorting in most cases, which is useful if
549
you want to use ORDER BY with this type.
553
HREF="cube.html#CUBE-FUNCTIONS-TABLE"
555
> shows the available functions.
560
NAME="CUBE-FUNCTIONS-TABLE"
564
>Table F-3. Cube Functions</B
574
>cube(float8) returns cube</TT
577
>Makes a one dimensional cube with both coordinates the same.
580
>cube(1) == '(1)'</TT
588
>cube(float8, float8) returns cube</TT
591
>Makes a one dimensional cube.
594
>cube(1,2) == '(1),(2)'</TT
602
>cube(float8[]) returns cube</TT
605
>Makes a zero-volume cube using the coordinates
606
defined by the array.
609
>cube(ARRAY[1,2]) == '(1,2)'</TT
617
>cube(float8[], float8[]) returns cube</TT
620
>Makes a cube with upper right and lower left
621
coordinates as defined by the two arrays, which must be of the
625
>cube('{1,2}'::float[], '{3,4}'::float[]) == '(1,2),(3,4)'
634
>cube(cube, float8) returns cube</TT
637
>Makes a new cube by adding a dimension on to an
638
existing cube with the same values for both parts of the new coordinate.
639
This is useful for building cubes piece by piece from calculated values.
642
>cube('(1)',2) == '(1,2),(1,2)'</TT
650
>cube(cube, float8, float8) returns cube</TT
653
>Makes a new cube by adding a dimension on to an
654
existing cube. This is useful for building cubes piece by piece from
655
calculated values. <TT
657
>cube('(1,2)',3,4) == '(1,3),(2,4)'</TT
665
>cube_dim(cube) returns int</TT
668
>Returns the number of dimensions of the cube
675
>cube_ll_coord(cube, int) returns double </TT
678
>Returns the n'th coordinate value for the lower left
686
>cube_ur_coord(cube, int) returns double
690
>Returns the n'th coordinate value for the
691
upper right corner of a cube
698
>cube_is_point(cube) returns bool</TT
701
>Returns true if a cube is a point, that is,
702
the two defining corners are the same.</TD
708
>cube_distance(cube, cube) returns double</TT
711
>Returns the distance between two cubes. If both
712
cubes are points, this is the normal distance function.
719
>cube_subset(cube, int[]) returns cube
723
>Makes a new cube from an existing cube, using a list of
724
dimension indexes from an array. Can be used to find both the LL and UR
725
coordinates of a single dimension, e.g.
728
>cube_subset(cube('(1,3,5),(6,7,8)'), ARRAY[2]) = '(3),(7)'</TT
730
Or can be used to drop dimensions, or reorder them as desired, e.g.
733
>cube_subset(cube('(1,3,5),(6,7,8)'), ARRAY[3,2,1,1]) = '(5, 3,
734
1, 1),(8, 7, 6, 6)'</TT
742
>cube_union(cube, cube) returns cube</TT
745
>Produces the union of two cubes
752
>cube_inter(cube, cube) returns cube</TT
755
>Produces the intersection of two cubes
762
>cube_enlarge(cube c, double r, int n) returns cube</TT
765
>Increases the size of a cube by a specified radius in at least
766
n dimensions. If the radius is negative the cube is shrunk instead. This
767
is useful for creating bounding boxes around a point for searching for
768
nearby points. All defined dimensions are changed by the radius r.
769
LL coordinates are decreased by r and UR coordinates are increased by r.
770
If a LL coordinate is increased to larger than the corresponding UR
771
coordinate (this can only happen when r < 0) than both coordinates
772
are set to their average. If n is greater than the number of defined
773
dimensions and the cube is being increased (r >= 0) then 0 is used
774
as the base for the extra coordinates.
790
> I believe this union:
793
CLASS="PROGRAMLISTING"
794
>select cube_union('(0,5,2),(2,3,1)', '0');
800
> does not contradict common sense, neither does the intersection
803
CLASS="PROGRAMLISTING"
804
>select cube_inter('(0,-1),(1,1)', '(-2),(2)');
810
> In all binary operations on differently-dimensioned cubes, I assume the
811
lower-dimensional one to be a Cartesian projection, i. e., having zeroes
812
in place of coordinates omitted in the string representation. The above
813
examples are equivalent to:
816
CLASS="PROGRAMLISTING"
817
>cube_union('(0,5,2),(2,3,1)','(0,0,0),(0,0,0)');
818
cube_inter('(0,-1),(1,1)','(-2,0),(2,0)');</PRE
820
> The following containment predicate uses the point syntax,
821
while in fact the second argument is internally represented by a box.
822
This syntax makes it unnecessary to define a separate point type
823
and functions for (box,point) predicates.
826
CLASS="PROGRAMLISTING"
827
>select cube_contains('(0,0),(1,1)', '0.5,0.5');
842
> For examples of usage, see the regression test <TT
848
> To make it harder for people to break things, there
849
is a limit of 100 on the number of dimensions of cubes. This is set
853
> if you need something bigger.
865
> Original author: Gene Selkov, Jr. <CODE
868
HREF="mailto:selkovjr@mcs.anl.gov"
869
>selkovjr@mcs.anl.gov</A
872
Mathematics and Computer Science Division, Argonne National Laboratory.
875
> My thanks are primarily to Prof. Joe Hellerstein
877
HREF="http://db.cs.berkeley.edu/jmh/"
879
>http://db.cs.berkeley.edu/jmh/</A
880
>) for elucidating the
882
HREF="http://gist.cs.berkeley.edu/"
884
>http://gist.cs.berkeley.edu/</A
886
to his former student, Andy Dong (<A
887
HREF="http://best.me.berkeley.edu/~adong/"
889
>http://best.me.berkeley.edu/~adong/</A
891
written for Illustra,
893
HREF="http://best.berkeley.edu/~adong/rtree/index.html"
895
>http://best.berkeley.edu/~adong/rtree/index.html</A
897
I am also grateful to all Postgres developers, present and past, for
898
enabling myself to create my own world and live undisturbed in it. And I
899
would like to acknowledge my gratitude to Argonne Lab and to the
900
U.S. Department of Energy for the years of faithful support of my database
904
> Minor updates to this package were made by Bruno Wolff III
908
HREF="mailto:bruno@wolff.to"
911
> in August/September of 2002. These include
912
changing the precision from single precision to double precision and adding
916
> Additional updates were made by Joshua Reich <CODE
919
HREF="mailto:josh@root.net"
923
July 2006. These include <TT
925
>cube(float8[], float8[])</TT
927
cleaning up the code to use the V1 call protocol instead of the deprecated
937
SUMMARY="Footer navigation table"
b'\\ No newline at end of file'