ProvSQL SQL API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
Temporal DB (PostgreSQL 14+)

Functions for temporal database support. More...

Functions

TSTZMULTIRANGE sr_temporal (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the temporal (interval-union) m-semiring.
nummultirange sr_interval_num (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the interval-union m-semiring with a NUMERIC multirange carrier.
int4multirange sr_interval_int (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the interval-union m-semiring with an int4 multirange carrier.
TSTZMULTIRANGE union_tstzintervals (UUID token, REGCLASS token2value)
 Evaluate temporal provenance as a TIMESTAMP multirange.
SETOF RECORD timetravel (TEXT tablename, TIMESTAMPTZ at_time)
 Query a table as it was at a specific point in time.
SETOF RECORD timeslice (TEXT tablename, TIMESTAMPTZ from_time, TIMESTAMPTZ to_time)
 Query a table for rows valid during a time interval.
SETOF RECORD history (TEXT tablename, TEXT[] col_names, TEXT[] col_values)
 Query the full temporal history of specific rows.
TSTZMULTIRANGE get_valid_time (UUID token, TEXT tablename)
 Get the valid time range for a specific tuple.
UUID undo (UUID c)
 Undo a previously recorded update operation.
UUID replace_the_circuit (UUID x, UUID c, UUID u)
 Recursively rewrite a circuit to undo a specific operation.

Variables

CREATE VIEW provsql time_validity_view AS SELECT valid_time AS value
 The base validity mapping is a plain view over the data-modification log: update_provenance is append-only and never has its provsql rewritten, so a view stays correct (unlike a tracked table's mapping, which must be a maintained mapping table ///< see create_provenance_mapping(maintained)).
CREATE VIEW provsql time_validity_view AS SELECT valid_time AS provsql AS provenance FROM provsql update_provenance

Detailed Description

Functions for temporal database support.

These use provenance evaluation over the multirange semiring to track temporal validity of tuples.

Function Documentation

◆ get_valid_time()

TSTZMULTIRANGE get_valid_time ( UUID token,
TEXT tablename )

Get the valid time range for a specific tuple.

Parameters
tokenprovenance token of the tuple
tablenamename of the table containing the tuple
Source code
provsql.sql line 11007

◆ history()

SETOF RECORD history ( TEXT tablename,
TEXT[] col_names,
TEXT[] col_values )

Query the full temporal history of specific rows.

Returns all versions of rows matching the given column values, with their temporal validity ranges.

Parameters
tablenamename of the provenance-tracked table
col_namesarray of column names to filter on
col_valuesarray of corresponding values to match

◆ replace_the_circuit()

UUID replace_the_circuit ( UUID x,
UUID c,
UUID u )

Recursively rewrite a circuit to undo a specific operation.

Helper for undo(). Walks the circuit and replaces occurrences of the target update gate with its monus.

Parameters
xprovenance token to rewrite
cUUID of the update operation to undo
uUUID of the undo operation
Source code
provsql.sql line 11133

◆ sr_interval_int()

int4multirange sr_interval_int ( ANYELEMENT token,
REGCLASS token2value )

Evaluate provenance over the interval-union m-semiring with an int4 multirange carrier.

Inputs are read as int4multirange validity ranges over the integers (e.g. page or line ranges of supporting documents). Addition is multirange union, multiplication is intersection, monus is set difference; the additive identity is '{}'::int4multirange and the multiplicative identity is '{(,)}'::int4multirange.

Parameters
tokenProvenance token to evaluate.
token2valueMapping from input gates to int4 multiranges.
Source code
provsql.sql line 10842

◆ sr_interval_num()

nummultirange sr_interval_num ( ANYELEMENT token,
REGCLASS token2value )

Evaluate provenance over the interval-union m-semiring with a NUMERIC multirange carrier.

Inputs are read as nummultirange validity ranges over a NUMERIC domain (e.g. sensor measurement-validity ranges). Addition is multirange union, multiplication is intersection, monus is set difference; the additive identity is '{}'::nummultirange and the multiplicative identity is '{(,)}'::nummultirange (universal range).

Parameters
tokenProvenance token to evaluate.
token2valueMapping from input gates to NUMERIC multiranges.
Source code
provsql.sql line 10815

◆ sr_temporal()

TSTZMULTIRANGE sr_temporal ( ANYELEMENT token,
REGCLASS token2value )

Evaluate provenance over the temporal (interval-union) m-semiring.

Inputs are read as TSTZMULTIRANGE validity intervals; the additive identity is '{}'::TSTZMULTIRANGE (empty), the multiplicative identity is '{(,)}'::TSTZMULTIRANGE (universal). Returns the union of intervals supporting the result, computed via the compiled circuit traversal.

Parameters
tokenProvenance token to evaluate.
token2valueMapping from input gates to validity multiranges.
Source code
provsql.sql line 10788

◆ timeslice()

SETOF RECORD timeslice ( TEXT tablename,
TIMESTAMPTZ from_time,
TIMESTAMPTZ to_time )

Query a table for rows valid during a time interval.

Returns all rows whose temporal validity overlaps the given range.

Parameters
tablenamename of the provenance-tracked table
from_timestart of the time interval
to_timeend of the time interval

◆ timetravel()

SETOF RECORD timetravel ( TEXT tablename,
TIMESTAMPTZ at_time )

Query a table as it was at a specific point in time.

Returns all rows whose temporal validity includes the given TIMESTAMP.

Parameters
tablenamename of the provenance-tracked table
at_timethe point in time to query

◆ undo()

UUID undo ( UUID c)

Undo a previously recorded update operation.

Traverses all provenance-tracked tables and rewrites their circuits to apply monus with respect to the given update token, effectively undoing the operation.

Parameters
cUUID of the update operation to undo (from update_provenance)
Source code
provsql.sql line 11045

◆ union_tstzintervals()

TSTZMULTIRANGE union_tstzintervals ( UUID token,
REGCLASS token2value )

Evaluate temporal provenance as a TIMESTAMP multirange.

Thin wrapper around :sqlfunc:sr_temporal retained for backward compatibility; both compute the same union of validity intervals.

Parameters
tokenprovenance token to evaluate
token2valuemapping table from tokens to temporal validity ranges
Source code
provsql.sql line 10864

Variable Documentation

◆ update_provenance

CREATE VIEW provsql time_validity_view AS SELECT valid_time AS provsql AS provenance FROM provsql update_provenance

◆ value

CREATE VIEW provsql time_validity_view AS SELECT valid_time AS value

The base validity mapping is a plain view over the data-modification log: update_provenance is append-only and never has its provsql rewritten, so a view stays correct (unlike a tracked table's mapping, which must be a maintained mapping table ///< see create_provenance_mapping(maintained)).