![]() |
ProvSQL SQL API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
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. | |
| UUID | substitute_gate (UUID x, UUID old, UUID new) |
| Rewrite a circuit, substituting one gate for another. | |
| UUID | replace_update (UUID old, DOUBLE PRECISION p) |
| Give a recorded data modification a different probability. | |
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 |
Functions for temporal database support.
These use provenance evaluation over the multirange semiring to track temporal validity of tuples.
| TSTZMULTIRANGE get_valid_time | ( | UUID | token, |
| TEXT | tablename ) |
Get the valid time range for a specific tuple.
| token | provenance token of the tuple |
| tablename | name of the table containing the tuple |
| 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.
| tablename | name of the provenance-tracked table |
| col_names | array of column names to filter on |
| col_values | array of corresponding values to match |
| 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.
| x | provenance token to rewrite |
| c | UUID of the update operation to undo |
| u | UUID of the undo operation |
| UUID replace_update | ( | UUID | old, |
| DOUBLE PRECISION | p ) |
Give a recorded data modification a different probability.
The update-gate counterpart of provsql.replace_input. A gate's probability is written once, so "how likely is it that this
modification happened" is changed by minting a new update gate with the new probability, logging it in update_provenance beside the one it replaces, and rewriting every tracked row whose provenance mentions the old gate to mention the new one instead – the same walk undo performs. The old gate and its log row are kept: the history of the database is not rewritten, it is extended.
| old | the update gate to replace, as found in update_provenance |
| p | the new probability, in [0,1] |
update gate | 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.
| token | Provenance token to evaluate. |
| token2value | Mapping from input gates to int4 multiranges. |
| 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).
| token | Provenance token to evaluate. |
| token2value | Mapping from input gates to NUMERIC multiranges. |
| 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.
| token | Provenance token to evaluate. |
| token2value | Mapping from input gates to validity multiranges. |
| UUID substitute_gate | ( | UUID | x, |
| UUID | old, | ||
| UUID | new ) |
Rewrite a circuit, substituting one gate for another.
Walks x and rebuilds every gate above an occurrence of old over new instead. Leaves that are not old come back unchanged, so a token that does not mention old is returned as it is.
| x | the token to rewrite |
| old | the gate to substitute away |
| new | the gate to put in its place |
| 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.
| tablename | name of the provenance-tracked table |
| from_time | start of the time interval |
| to_time | end of the time interval |
| 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.
| tablename | name of the provenance-tracked table |
| at_time | the point in time to query |
| 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.
| c | UUID of the update operation to undo (from update_provenance) |
| 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.
| token | provenance token to evaluate |
| token2value | mapping table from tokens to temporal validity ranges |
| CREATE VIEW provsql time_validity_view AS SELECT valid_time AS provsql AS provenance FROM provsql update_provenance |
| 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)).