Skip to main content
Use vsql_cube when several numeric columns belong together and you want to query them as a single value. A chain of AND conditions can test whether a row falls inside a range, but it cannot rank rows by distance. The cube type does both. It is a port of PostgreSQL’s cube extension. Most PostgreSQL function names carry over; the cube() constructors, the operators and their support functions (cube_contained, cube_overlap, distance_taxicab, distance_chebyshev) become the named functions below.

Install

vsql_cube.veb is already in the server’s lib/veb/ directory if you installed VillageSQL with the install script, the Docker image, or a release tarball. Install it into the server with one statement:
Confirm it is there:
To build it yourself, follow the build instructions in the repository.

What it adds

The cube type

Declare the column as `cube`(N), where N is the largest number of dimensions a value can have, from 1 to 100. cube is a MySQL reserved word, so it needs backticks, and the dimension count is required.
Write values as a coordinate string. The column parses it:

Functions

Example

Find the two sensors nearest a target reading, then the sensors inside a region:
A cube argument gets its dimension count from a column, so a call works when one of its cube arguments is a column value or the result of a function that keeps a column’s dimension count, such as cube_union or cube_enlarge. A call with no such argument, as in cube_dim(cube_point_nd(1, 2)), fails with ERROR 3219 (HY000): Cannot initialize function 'cube_dim': cannot determine type parameters for vsql_cube.cube in argument 1. For the same reason, insert a plain coordinate string rather than wrapping it in cube_point_nd().Each argument to cube_point_nd, cube_box_nd and cube_subset may also be a comma-separated string, and the lists join end to end. So cube_point_nd('1,2,3') and cube_point_nd(1, 2, 3) build the same point. Pass a string when the coordinates live in a column, which is the one case separate arguments cannot express.

See also