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. Where PostgreSQL has a named function the name matches, and PostgreSQL’s operators and array constructors 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 number of dimensions. 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 the column it came from, so every call above passes a column value. Feeding one function’s result straight into another, 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().

See also