Table of Contents
The temporal QUADBIN cell index type tquadbin represents the movement of objects as a sequence of QUADBIN square cell identifiers. CARTO's QUADBIN is a hierarchical square grid system built on the slippy-map (web-mercator) tile scheme: a single world cell at resolution 0 subdivides into four equal children at every finer resolution (up to 26). Each cell has a 64-bit integer identifier that encodes a header tag, the resolution, and the tile coordinates of the cell.
The tquadbin type shares its on-disk representation with tbigint: both store a temporal 64-bit integer. The distinct SQL type exists purely to let the type-checker reject quadbin-specific functions when applied to arbitrary bigint trajectories (and vice-versa). Casts to / from tbigint are explicit (AS ASSIGNMENT) and binary-coercion only, zero-cost at runtime but requiring an explicit :: in SQL.
As with other temporal types, tquadbin has four subtypes: Instant, discrete-sequence, continuous-sequence with step interpolation (QUADBIN cells are discrete, linear interpolation is meaningless), and SequenceSet.
A tquadbin value is entered using the standard temporal syntax with the underlying 64-bit QUADBIN cell identifier. The input parser accepts the canonical hexadecimal form, with an optional 0x prefix, in either letter case, as the CARTO reference implementation reads it. Hexadecimal is idiomatic in the QUADBIN ecosystem and is what the output function emits, all examples below use it. For reference, the hex value 480fffffffffffff used in the examples is the resolution-0 world cell, equal to the decimal value 5192650370358181887.
SELECT tquadbin '480fffffffffffff@2001-01-01';
SELECT tquadbin '{480fffffffffffff@2001-01-01, 48427fffffffffff@2001-01-02}';
SELECT tquadbin '[480fffffffffffff@2001-01-01, 48427fffffffffff@2001-01-02]';
SELECT tquadbin '{[480fffffffffffff@2001-01-01, 48427fffffffffff@2001-01-02],
[48a6227affffffff@2001-01-03, 485623ffffffffff@2001-01-04]}';
The type accepts type modifiers (typmod) to constrain a column to a specific subtype: Instant, Sequence, or SequenceSet.
SELECT tquadbin(Instant) '480fffffffffffff@2001-01-01';
SELECT tquadbin(SequenceSet) '{[480fffffffffffff@2001-01-01, 48427fffffffffff@2001-01-02]}';
-- ERROR: temporal type (Instant) does not match column type (Sequence)
SELECT tquadbin(Sequence) '480fffffffffffff@2001-01-01';
The functions asText, asBinary, and asHexWKB serialize a tquadbin value, and tquadbinFromBinary and tquadbinFromHexWKB reconstruct it. The hexadecimal WKB form lets a temporal QUADBIN index column round-trip through a text-based COPY.
SELECT asHexWKB(tquadbin '480fffffffffffff@2001-01-01'); SELECT tquadbinFromHexWKB(asHexWKB(tquadbin '480fffffffffffff@2001-01-01')); -- 480fffffffffffff@2001-01-01
The MF-JSON representation is available through asMFJSON(tquadbin) and tquadbinFromMFJSON(text). The cell payload renders as the int64 cell identifier in the values array, the same representation carried by tbigint.
SELECT asMFJSON(tquadbin '480fffffffffffff@2001-01-01'); SELECT tquadbinFromMFJSON(asMFJSON(tquadbin '480fffffffffffff@2001-01-01')); -- 480fffffffffffff@2001-01-01