Database Reference
In-Depth Information
Cube
The cube extension is used to create multidimensional data. It is useful for datasets that
require more than one dimension. Through this extension, you can perform many opera-
tions with multidimensional data such as discovering the number of dimensions, creating
union between cubes, finding the intersection of two cubes, generating subsets, and other
functions. In the following example, you will see how to create a cube and how to perform
some queries.
$ heroku pg:psql --app your-app-name
CREATE EXTENSION cube;
CREATE TABLE sets (element cube);
INSERT INTO sets (element) VALUES ('(1, 2, 3)');
First, you'll check whether the cube contains a specific subset:
SELECT * FROM sets WHERE cube_contains(element, '(1, 2)');
element
-----------
(1, 2, 3)
After that, you'll create a cube union with another cube:
SELECT cube_union(element, '(4, 5, 6)') FROM sets;
cube_union
---------------------
(1, 2, 3),(4, 5, 6)
Finally, you will find the cube intersection with another cube:
SELECT cube_inter(element, '(1, 2)') FROM sets;
cube_inter
---------------------
(1, 2, 3),(1, 2, 0)
There are other functions that you can explore. For more information, visit the website ht-
tp://www.postgresql.org/docs/current/static/cube.html .
Search WWH ::




Custom Search