![]() |
ProvSQL SQL API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Row type for sub_circuit_with_desc results. More...
Topics | |
| Type for continuous random variables | |
| Input function for the AGG_TOKEN type (parses TEXT representation). | |
Functions | |
| AGG_TOKEN | agg_token_in (CSTRING) |
| Input function for the AGG_TOKEN type (parses TEXT representation). | |
| CSTRING | agg_token_out (AGG_TOKEN) |
| Output function for the AGG_TOKEN type. | |
| TEXT | agg_token_cast (AGG_TOKEN) |
| Cast an AGG_TOKEN to its TEXT representation. | |
| UUID | agg_token_uuid (AGG_TOKEN aggtok) |
| Extract the UUID from an AGG_TOKEN (implicit cast to UUID). | |
| UUID | CAST(AGG_TOKEN AS UUID) (AGG_TOKEN) |
| Implicit PostgreSQL cast from AGG_TOKEN to UUID (delegates to agg_token_uuid()). | |
| TEXT | agg_token_value_text (UUID token) |
Recover the "value (*)" display string for an aggregation gate. | |
| NUMERIC | agg_token_to_numeric (AGG_TOKEN) |
| Cast an AGG_TOKEN to NUMERIC (extracts the aggregate value, loses provenance). | |
| DOUBLE PRECISION | agg_token_to_float8 (AGG_TOKEN) |
| Cast an AGG_TOKEN to DOUBLE PRECISION (extracts the aggregate value, loses provenance). | |
| INTEGER | agg_token_to_int4 (AGG_TOKEN) |
| Cast an AGG_TOKEN to INTEGER (extracts the aggregate value, loses provenance). | |
| bigint | agg_token_to_int8 (AGG_TOKEN) |
| Cast an AGG_TOKEN to bigint (extracts the aggregate value, loses provenance). | |
| TEXT | agg_token_to_text (AGG_TOKEN) |
| Cast an AGG_TOKEN to TEXT (extracts the aggregate value, loses provenance). | |
| CREATE | CAST (AGG_TOKEN AS NUMERIC) WITH FUNCTION agg_token_to_numeric(AGG_TOKEN) AS ASSIGNMENT |
| Assignment cast from AGG_TOKEN to NUMERIC (extracts the scalar value, dropping provenance). | |
| NUMERIC | agg_token_value (AGG_TOKEN) |
| Arithmetic on aggregates (AGG_TOKEN) Mirrors the random_variable arithmetic surface: the operators build a gate_arith over the operand provenance UUIDs (via provenance_arith, info1 = PROVSQL_ARITH_*), so the arithmetic is recorded symbolically in the circuit and can be resolved when a comparison (gate_cmp) over the result is evaluated. | |
| AGG_TOKEN | agg_token_make (UUID tok, NUMERIC val) |
| Bundle a provenance gate UUID with a running value into an AGG_TOKEN (inverse of the agg_token_uuid / agg_token_value accessors). | |
| UUID | agg_value_gate (NUMERIC v) |
| Lift a scalar NUMERIC constant into a gate_value leaf and return its UUID, so it can be a child of a gate_arith (the agg-side analogue of as_random for random_variable). | |
| AGG_TOKEN | agg_arith_make (INT op, UUID[] children, NUMERIC val) |
| Mint (or reuse) the gate_arith for an AGG_TOKEN arithmetic result and return the AGG_TOKEN carrying it. | |
| AGG_TOKEN | agg_token_plus (AGG_TOKEN a, AGG_TOKEN b) |
| AGG_TOKEN <op> AGG_TOKEN | |
| AGG_TOKEN | agg_token_minus (AGG_TOKEN a, AGG_TOKEN b) |
| AGG_TOKEN - AGG_TOKEN (gate_arith MINUS). | |
| AGG_TOKEN | agg_token_times (AGG_TOKEN a, AGG_TOKEN b) |
| AGG_TOKEN * AGG_TOKEN (gate_arith TIMES). | |
| AGG_TOKEN | agg_token_div (AGG_TOKEN a, AGG_TOKEN b) |
| AGG_TOKEN / AGG_TOKEN (gate_arith DIV). | |
| AGG_TOKEN | agg_token_neg (AGG_TOKEN a) |
| Unary -AGG_TOKEN (gate_arith NEG). | |
| AGG_TOKEN | agg_token_plus_numeric (AGG_TOKEN a, NUMERIC b) |
| AGG_TOKEN <op> NUMERIC | |
| AGG_TOKEN | agg_token_minus_numeric (AGG_TOKEN a, NUMERIC b) |
| AGG_TOKEN - NUMERIC. | |
| AGG_TOKEN | agg_token_times_numeric (AGG_TOKEN a, NUMERIC b) |
| AGG_TOKEN * NUMERIC. | |
| AGG_TOKEN | agg_token_div_numeric (AGG_TOKEN a, NUMERIC b) |
| AGG_TOKEN / NUMERIC. | |
| AGG_TOKEN | numeric_plus_agg_token (NUMERIC a, AGG_TOKEN b) |
| NUMERIC <op> AGG_TOKEN | |
| AGG_TOKEN | numeric_minus_agg_token (NUMERIC a, AGG_TOKEN b) |
| NUMERIC - AGG_TOKEN. | |
| AGG_TOKEN | numeric_times_agg_token (NUMERIC a, AGG_TOKEN b) |
| NUMERIC * AGG_TOKEN. | |
| AGG_TOKEN | numeric_div_agg_token (NUMERIC a, AGG_TOKEN b) |
| NUMERIC / AGG_TOKEN. | |
| BOOLEAN | agg_token_op_agg_token (AGG_TOKEN left, AGG_TOKEN right) |
| Operator declarations. | |
| BOOLEAN | agg_token_op_numeric (AGG_TOKEN left, NUMERIC right) |
| BOOLEAN | numeric_op_agg_token (NUMERIC left, AGG_TOKEN right) |
| AGG_TOKEN | agg_token_cond (AGG_TOKEN a, UUID cond) |
Condition a discrete aggregate's distribution on an event: "SUM(x) | C". | |
| BOOLEAN | agg_token_op_uuid (AGG_TOKEN left, UUID right) |
| AGG_TOKEN | agg_token_cond_predicate (AGG_TOKEN a, BOOLEAN predicate) |
Placeholder for "SUM(x) | (predicate)" on an AGG_TOKEN. | |
| BOOLEAN | agg_token_op_boolean (AGG_TOKEN left, BOOLEAN right) |
| AGG_TOKEN | agg_conditioned_target (AGG_TOKEN a) |
Unpack the target of a conditioned AGG_TOKEN. | |
| BOOLEAN | agg_token_comp_numeric (AGG_TOKEN a, NUMERIC b) |
| Placeholder comparison of AGG_TOKEN with NUMERIC. | |
| BOOLEAN | numeric_comp_agg_token (NUMERIC a, AGG_TOKEN b) |
| Placeholder comparison of NUMERIC with AGG_TOKEN. | |
| BOOLEAN | agg_token_lt_numeric (AGG_TOKEN left, NUMERIC right) |
| SQL operator AGG_TOKEN < NUMERIC (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | numeric_lt_agg_token (NUMERIC left, AGG_TOKEN right) |
| SQL operator NUMERIC < AGG_TOKEN (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | agg_token_le_numeric (AGG_TOKEN left, NUMERIC right) |
| SQL operator AGG_TOKEN <= NUMERIC (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | numeric_le_agg_token (NUMERIC left, AGG_TOKEN right) |
| SQL operator NUMERIC <= AGG_TOKEN (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | agg_token_eq_numeric (AGG_TOKEN left, NUMERIC right) |
| SQL operator AGG_TOKEN = NUMERIC (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | numeric_eq_agg_token (NUMERIC left, AGG_TOKEN right) |
| SQL operator NUMERIC = AGG_TOKEN (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | agg_token_ne_numeric (AGG_TOKEN left, NUMERIC right) |
| SQL operator AGG_TOKEN <> NUMERIC (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | numeric_ne_agg_token (NUMERIC left, AGG_TOKEN right) |
| SQL operator NUMERIC <> AGG_TOKEN (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | agg_token_ge_numeric (AGG_TOKEN left, NUMERIC right) |
| SQL operator AGG_TOKEN >= NUMERIC (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | numeric_ge_agg_token (NUMERIC left, AGG_TOKEN right) |
| SQL operator NUMERIC >= AGG_TOKEN (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | agg_token_gt_numeric (AGG_TOKEN left, NUMERIC right) |
| SQL operator AGG_TOKEN > NUMERIC (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | numeric_gt_agg_token (NUMERIC left, AGG_TOKEN right) |
| SQL operator NUMERIC > AGG_TOKEN (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | agg_token_comp_agg_token (AGG_TOKEN a, AGG_TOKEN b) |
| Placeholder comparison of two AGG_TOKEN values (the diagonal). | |
| BOOLEAN | agg_token_lt_agg_token (AGG_TOKEN left, AGG_TOKEN right) |
| SQL operator AGG_TOKEN < AGG_TOKEN (placeholder rewritten at plan time). | |
| BOOLEAN | agg_token_le_agg_token (AGG_TOKEN left, AGG_TOKEN right) |
| SQL operator AGG_TOKEN <= AGG_TOKEN (placeholder rewritten at plan time). | |
| BOOLEAN | agg_token_gt_agg_token (AGG_TOKEN left, AGG_TOKEN right) |
| SQL operator AGG_TOKEN > AGG_TOKEN (placeholder rewritten at plan time). | |
| BOOLEAN | agg_token_ge_agg_token (AGG_TOKEN left, AGG_TOKEN right) |
| SQL operator AGG_TOKEN >= AGG_TOKEN (placeholder rewritten at plan time). | |
| BOOLEAN | agg_token_eq_agg_token (AGG_TOKEN left, AGG_TOKEN right) |
| SQL operator AGG_TOKEN = AGG_TOKEN (placeholder rewritten at plan time). | |
| BOOLEAN | agg_token_ne_agg_token (AGG_TOKEN left, AGG_TOKEN right) |
| SQL operator AGG_TOKEN <> AGG_TOKEN (placeholder rewritten at plan time). | |
| BOOLEAN | agg_token_comp_text (AGG_TOKEN a, TEXT b) |
| Placeholder comparison of AGG_TOKEN with TEXT. | |
| BOOLEAN | text_comp_agg_token (TEXT a, AGG_TOKEN b) |
| Placeholder comparison of TEXT with AGG_TOKEN. | |
| BOOLEAN | agg_token_eq_text (AGG_TOKEN left, TEXT right) |
| SQL operator AGG_TOKEN = TEXT (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | text_eq_agg_token (TEXT left, AGG_TOKEN right) |
| SQL operator TEXT = AGG_TOKEN (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | agg_token_ne_text (AGG_TOKEN left, TEXT right) |
| SQL operator AGG_TOKEN <> TEXT (placeholder rewritten by ProvSQL at plan time). | |
| BOOLEAN | text_ne_agg_token (TEXT left, AGG_TOKEN right) |
| SQL operator TEXT <> AGG_TOKEN (placeholder rewritten by ProvSQL at plan time). | |
Row type for sub_circuit_with_desc results.
Custom type AGG_TOKEN for a provenance semimodule value, to be used in attributes that are computed as a result of aggregation.
Return the sub-circuit reachable from a token, with descriptions
Recursively traverses the provenance circuit from the given token and returns all edges together with input gate descriptions from the mapping table.
| token | root provenance token |
| token2desc | mapping table providing descriptions for input gates |
Identify which table and how many columns a provenance token belongs to
Searches all provenance-tracked tables for a row matching the given token and returns the table name and column count.
| token | provenance token to look up |
| table_name | (OUT) the table containing this token |
| nb_columns | (OUT) number of non-provenance columns in that table |
Return the sub-circuit for where-provenance computation
Similar to sub_circuit_with_desc but resolves input gates to their source table and column count for where-provenance evaluation.
BFS expansion of a provenance circuit, capped at max_depth
Returns one row per (parent, child) edge in the BFS-bounded subgraph rooted at root, plus one row for the root with parent and child_pos NULL. Provenance circuits are DAGs, so a child gate may have several parents within the bound; each such edge is reported as a separate row, so callers must deduplicate on node if they need a one-row-per-node view.
depth is the node's BFS depth (its shortest distance from root), so for an edge (parent, child) it is always the case that parent.depth + 1 >= child.depth; equality holds only on shortest-path edges. A node at depth = max_depth is not expanded; callers can detect a partial expansion by comparing provsql.get_children length against the number of outgoing edges reported.
info1 and info2 are the INTEGER values stored on the gate by provsql.set_infos, formatted as TEXT; their meaning is gate-type-specific (see provsql.set_infos).
| root | root provenance token |
| max_depth | maximum BFS depth (default 8) |
BFS subgraph of the IN-MEMORY simplified circuit rooted at root.
Same row shape as circuit_subgraph plus an inline extra column, but built from the GenericCircuit returned by getGenericCircuit – i.e. AFTER provsql.simplify_on_load passes (RangeCheck, ...) have rewritten any decidable gate_cmp into Bernoulli gate_input / gate_zero / gate_one leaves. Lets a renderer show the user what the evaluator actually sees, without mutating the persisted DAG.
Returns jsonb (an array of objects) rather than SETOF RECORD
to keep the C++ implementation free of SRF / FuncCallContext boilerplate; callers either consume the array directly or expand it via jsonb_array_elements.
| root | Root provenance token. |
| max_depth | Maximum BFS depth (default 8). |
Empirical histogram of a scalar sub-circuit
Returns a jsonb array of {bin_lo, bin_hi, count} objects covering the observed [min, max] range of bins equal-width samples from the sub-circuit rooted at token. Sample count is taken from provsql.rv_mc_samples; pinning provsql.monte_carlo_seed makes the result reproducible.
Accepted root gate types are the scalar ones: gate_value (Dirac at the constant, single bin), gate_rv (sampled from the leaf's distribution), and gate_arith (sampled by recursing through the arithmetic DAG, with shared gate_rv leaves correctly correlated within an iteration). Any other gate type raises.
| token | Root provenance token of a scalar sub-circuit. |
| bins | Number of equal-width histogram bins (default 30). |
| prov | Conditioning event (defaults to gate_one() = no conditioning). When non-trivial, the histogram is over the conditional distribution recovered by rejection sampling on the joint circuit with token. |
Sample the closed-form PDF and CDF of a (possibly truncated) scalar distribution.
Returns {"pdf": [{x, p}, ...], "cdf": [{x, p}, ...]} with samples evenly-spaced points spanning the distribution's natural display range (intersected with the conditioning event's interval when prov is non-trivial). Used by ProvSQL Studio's Distribution profile panel to overlay the analytical curve on the empirical histogram from :sqlfunc:rv_histogram – the simplifier's analytical wins (e.g. c·Exp(λ) folding to Exp(λ/c)) become visible as a smooth curve riding over the MC-sampled bars.
Returns NULL when the root sub-circuit is not a closed-form shape (V1: only bare gate_rv of Normal / Uniform / Exponential / INTEGER-Erlang). The frontend reads NULL as "skip overlay" without erroring, so the caller can dispatch this in parallel with rv_histogram regardless of the underlying shape.
| token | Scalar gate token (random_variable's UUID). |
| samples | Number of (x, p) points; must be >= 2. |
| prov | Conditioning event (defaults to gate_one() = no conditioning). When non-trivial, the curves are over the truncated distribution. |
Draw conditional Monte Carlo samples from a scalar gate.
Returns up to n samples of the scalar value at token; when prov is not the trivial gate_one() event, draws are accepted only on iterations where prov evaluates true (rejection sampling). Shared gate_rv leaves between token and prov are loaded into a single joint circuit so the indicator's draw and the value's draw share their per-iteration state.
| token | Scalar sub-circuit root. |
| n | Number of accepted samples to attempt. |
| prov | Conditioning event (defaults to gate_one() = no conditioning). |
Emits a NOTICE when the conditional acceptance rate yields fewer than n samples within the provsql.rv_mc_samples budget so the caller can choose to widen the budget.
Resolve an input gate UUID back to its source row
Searches every provenance-tracked relation for a row whose provsql column equals UUID and returns the relation's REGCLASS together with the row encoded as JSONB. Returns zero rows when UUID is not the provenance token of any tracked row, including when it identifies an internal gate (plus, times, ...) rather than an input.
Ordinarily exactly one row is returned, but if the same UUID happens to appear as a provsql value in several tracked tables, all matches are returned.
| UUID | token to resolve |
Custom type AGG_TOKEN for a provenance semimodule value, to be used in attributes that are computed as a result of aggregation. As for provenance tokens, this is simply a UUID, but this UUID is displayed in a specific way (as the result of the aggregation followed by a "(*)") to help with readability.
The TEXT output is controlled by the provsql.aggtoken_text_as_uuid GUC. By default it is off and the cell renders as "value (*)". When set to on (typical for UI layers such as ProvSQL Studio), the cell renders as the underlying UUID instead, so the caller can click through to the provenance circuit; the value side is then recovered via provsql.agg_token_value_text(UUID).
As for provenance tokens, this is simply a UUID, but this UUID is displayed in a specific way (as the result of the aggregation followed by a "(*)") to help with readability.
The TEXT output is controlled by the provsql.aggtoken_text_as_uuid GUC. By default it is off and the cell renders as "value (*)". When set to on (typical for UI layers such as ProvSQL Studio), the cell renders as the underlying UUID instead, so the caller can click through to the provenance circuit; the value side is then recovered via provsql.agg_token_value_text(UUID).
| AGG_TOKEN update_provenance::agg_arith_make | ( | INT | op, |
| UUID[] | children, | ||
| NUMERIC | val ) |
Mint (or reuse) the gate_arith for an AGG_TOKEN arithmetic result and return the AGG_TOKEN carrying it.
Also records the computed scalar in the gate's extra – exactly what aggregate evaluation does for agg gates – so agg_token_value_text can recover the "value (*)" display from the bare UUID (as ProvSQL Studio does for result cells under provsql.aggtoken_text_as_uuid). The gate UUID is deterministic in (op, children), so re-recording the (identical) value is idempotent.
| AGG_TOKEN update_provenance::agg_conditioned_target | ( | AGG_TOKEN | a | ) |
Unpack the target of a conditioned AGG_TOKEN.
For a "SUM(x) | C" whose provenance token is the two-child gate_conditioned [agg_target, condition] returns the AGG_TOKEN over agg_target (same running value); for any other AGG_TOKEN returns it unchanged. The conditioning event itself is recovered separately via rv_conditioned_prov on the token's UUID.
| TEXT update_provenance::agg_token_cast | ( | AGG_TOKEN | ) |
Cast an AGG_TOKEN to its TEXT representation.
| BOOLEAN update_provenance::agg_token_comp_agg_token | ( | AGG_TOKEN | a, |
| AGG_TOKEN | b ) |
Placeholder comparison of two AGG_TOKEN values (the diagonal).
Never actually called; lets the parser accept AGG_TOKEN <op> AGG_TOKEN (e.g. sum(x) > sum(y) on materialised tokens), which the ProvSQL rewriter lowers to a gate_cmp at plan time. Declaring this diagonal also disambiguates s = s2 (otherwise "operator is not unique", because both AGG_TOKEN -> UUID and AGG_TOKEN -> NUMERIC casts apply).
| BOOLEAN update_provenance::agg_token_comp_numeric | ( | AGG_TOKEN | a, |
| NUMERIC | b ) |
Placeholder comparison of AGG_TOKEN with NUMERIC.
This function is never actually called; it exists so the SQL parser accepts comparison operators between AGG_TOKEN and NUMERIC values. The ProvSQL query rewriter replaces these comparisons at plan time.
| BOOLEAN update_provenance::agg_token_comp_text | ( | AGG_TOKEN | a, |
| TEXT | b ) |
Placeholder comparison of AGG_TOKEN with TEXT.
This function is never actually called; it exists so the SQL parser accepts comparison operators between AGG_TOKEN and TEXT values. The ProvSQL query rewriter replaces these comparisons at plan time.
| AGG_TOKEN update_provenance::agg_token_cond | ( | AGG_TOKEN | a, |
| UUID | cond ) |
Condition a discrete aggregate's distribution on an event: "SUM(x) | C".
Mirrors random_variable_cond for the AGG_TOKEN carrier: returns a conditioned AGG_TOKEN that flows onward, its provenance token wrapped in the composable two-child gate_conditioned [agg_target, condition] while its running value is preserved. The moment / support dispatchers unpack it (agg_conditioned_target + rv_conditioned_prov) and route through the existing agg_raw_moment with the condition conjoined into the prov argument, so expected(SUM(x)|C) / variance(SUM(x)|C) report the conditional aggregate distribution. Nested conditioning folds.
| AGG_TOKEN update_provenance::agg_token_cond_predicate | ( | AGG_TOKEN | a, |
| BOOLEAN | predicate ) |
Placeholder for "SUM(x) | (predicate)" on an AGG_TOKEN.
Lets the conditioning event be a natural Boolean predicate (e.g. "SUM(x) | (SUM(x) > 5)") instead of a hand-built gate. Never executes: the planner converts the Boolean operand into a condition gate and emits agg_token_cond.
| AGG_TOKEN update_provenance::agg_token_div | ( | AGG_TOKEN | a, |
| AGG_TOKEN | b ) |
AGG_TOKEN / AGG_TOKEN (gate_arith DIV).
| AGG_TOKEN update_provenance::agg_token_div_numeric | ( | AGG_TOKEN | a, |
| NUMERIC | b ) |
AGG_TOKEN / NUMERIC.
| BOOLEAN update_provenance::agg_token_eq_agg_token | ( | AGG_TOKEN | left, |
| AGG_TOKEN | right ) |
SQL operator AGG_TOKEN = AGG_TOKEN (placeholder rewritten at plan time).
| BOOLEAN update_provenance::agg_token_eq_numeric | ( | AGG_TOKEN | left, |
| NUMERIC | right ) |
SQL operator AGG_TOKEN = NUMERIC (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::agg_token_eq_text | ( | AGG_TOKEN | left, |
| TEXT | right ) |
SQL operator AGG_TOKEN = TEXT (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::agg_token_ge_agg_token | ( | AGG_TOKEN | left, |
| AGG_TOKEN | right ) |
SQL operator AGG_TOKEN >= AGG_TOKEN (placeholder rewritten at plan time).
| BOOLEAN update_provenance::agg_token_ge_numeric | ( | AGG_TOKEN | left, |
| NUMERIC | right ) |
SQL operator AGG_TOKEN >= NUMERIC (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::agg_token_gt_agg_token | ( | AGG_TOKEN | left, |
| AGG_TOKEN | right ) |
SQL operator AGG_TOKEN > AGG_TOKEN (placeholder rewritten at plan time).
| BOOLEAN update_provenance::agg_token_gt_numeric | ( | AGG_TOKEN | left, |
| NUMERIC | right ) |
SQL operator AGG_TOKEN > NUMERIC (placeholder rewritten by ProvSQL at plan time).
| AGG_TOKEN update_provenance::agg_token_in | ( | CSTRING | ) |
Input function for the AGG_TOKEN type (parses TEXT representation).
| BOOLEAN update_provenance::agg_token_le_agg_token | ( | AGG_TOKEN | left, |
| AGG_TOKEN | right ) |
SQL operator AGG_TOKEN <= AGG_TOKEN (placeholder rewritten at plan time).
| BOOLEAN update_provenance::agg_token_le_numeric | ( | AGG_TOKEN | left, |
| NUMERIC | right ) |
SQL operator AGG_TOKEN <= NUMERIC (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::agg_token_lt_agg_token | ( | AGG_TOKEN | left, |
| AGG_TOKEN | right ) |
SQL operator AGG_TOKEN < AGG_TOKEN (placeholder rewritten at plan time).
| BOOLEAN update_provenance::agg_token_lt_numeric | ( | AGG_TOKEN | left, |
| NUMERIC | right ) |
SQL operator AGG_TOKEN < NUMERIC (placeholder rewritten by ProvSQL at plan time).
| AGG_TOKEN update_provenance::agg_token_make | ( | UUID | tok, |
| NUMERIC | val ) |
Bundle a provenance gate UUID with a running value into an AGG_TOKEN (inverse of the agg_token_uuid / agg_token_value accessors).
| AGG_TOKEN update_provenance::agg_token_minus | ( | AGG_TOKEN | a, |
| AGG_TOKEN | b ) |
AGG_TOKEN - AGG_TOKEN (gate_arith MINUS).
| AGG_TOKEN update_provenance::agg_token_minus_numeric | ( | AGG_TOKEN | a, |
| NUMERIC | b ) |
AGG_TOKEN - NUMERIC.
| BOOLEAN update_provenance::agg_token_ne_agg_token | ( | AGG_TOKEN | left, |
| AGG_TOKEN | right ) |
SQL operator AGG_TOKEN <> AGG_TOKEN (placeholder rewritten at plan time).
| BOOLEAN update_provenance::agg_token_ne_numeric | ( | AGG_TOKEN | left, |
| NUMERIC | right ) |
SQL operator AGG_TOKEN <> NUMERIC (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::agg_token_ne_text | ( | AGG_TOKEN | left, |
| TEXT | right ) |
SQL operator AGG_TOKEN <> TEXT (placeholder rewritten by ProvSQL at plan time).
| AGG_TOKEN update_provenance::agg_token_neg | ( | AGG_TOKEN | a | ) |
Unary -AGG_TOKEN (gate_arith NEG).
| BOOLEAN agg_token_op_agg_token | ( | AGG_TOKEN | left, |
| AGG_TOKEN | right ) |
Operator declarations.
| BOOLEAN update_provenance::agg_token_op_boolean | ( | AGG_TOKEN | left, |
| BOOLEAN | right ) |
| BOOLEAN agg_token_op_numeric | ( | AGG_TOKEN | left, |
| NUMERIC | right ) |
| BOOLEAN update_provenance::agg_token_op_uuid | ( | AGG_TOKEN | left, |
| UUID | right ) |
| CSTRING update_provenance::agg_token_out | ( | AGG_TOKEN | ) |
Output function for the AGG_TOKEN type.
Default: produces the human-friendly "value (*)" form, where value is the running aggregate state.
When the provsql.aggtoken_text_as_uuid GUC is on, returns the underlying provenance UUID instead. UI layers (notably ProvSQL Studio) flip this on per session so aggregate cells expose the circuit root UUID for click-through; the "value (*)" display string is recovered via provsql.agg_token_value_text(UUID).
Marked STABLE rather than IMMUTABLE because the chosen output shape now depends on a GUC that the same session can flip at runtime.
| AGG_TOKEN update_provenance::agg_token_plus | ( | AGG_TOKEN | a, |
| AGG_TOKEN | b ) |
| AGG_TOKEN update_provenance::agg_token_plus_numeric | ( | AGG_TOKEN | a, |
| NUMERIC | b ) |
AGG_TOKEN <op> NUMERIC
AGG_TOKEN + NUMERIC (gate_arith PLUS, constant lifted to a value gate).
| AGG_TOKEN update_provenance::agg_token_times | ( | AGG_TOKEN | a, |
| AGG_TOKEN | b ) |
AGG_TOKEN * AGG_TOKEN (gate_arith TIMES).
| AGG_TOKEN update_provenance::agg_token_times_numeric | ( | AGG_TOKEN | a, |
| NUMERIC | b ) |
AGG_TOKEN * NUMERIC.
| DOUBLE PRECISION update_provenance::agg_token_to_float8 | ( | AGG_TOKEN | ) |
Cast an AGG_TOKEN to DOUBLE PRECISION (extracts the aggregate value, loses provenance).
| INTEGER update_provenance::agg_token_to_int4 | ( | AGG_TOKEN | ) |
Cast an AGG_TOKEN to INTEGER (extracts the aggregate value, loses provenance).
| bigint update_provenance::agg_token_to_int8 | ( | AGG_TOKEN | ) |
Cast an AGG_TOKEN to bigint (extracts the aggregate value, loses provenance).
| NUMERIC update_provenance::agg_token_to_numeric | ( | AGG_TOKEN | ) |
Cast an AGG_TOKEN to NUMERIC (extracts the aggregate value, loses provenance).
| TEXT update_provenance::agg_token_to_text | ( | AGG_TOKEN | ) |
Cast an AGG_TOKEN to TEXT (extracts the aggregate value, loses provenance).
| UUID update_provenance::agg_token_uuid | ( | AGG_TOKEN | aggtok | ) |
Extract the UUID from an AGG_TOKEN (implicit cast to UUID).
| NUMERIC update_provenance::agg_token_value | ( | AGG_TOKEN | ) |
Arithmetic on aggregates (AGG_TOKEN) Mirrors the random_variable arithmetic surface: the operators build a gate_arith over the operand provenance UUIDs (via provenance_arith, info1 = PROVSQL_ARITH_*), so the arithmetic is recorded symbolically in the circuit and can be resolved when a comparison (gate_cmp) over the result is evaluated.
Unlike random_variable (a bare UUID), an AGG_TOKEN also carries a running scalar value, so each operator additionally computes the resulting value and bundles it back with the new gate.
Running value of an AGG_TOKEN as NUMERIC, without the provenance-loss warning the public cast emits (internal use).
| TEXT update_provenance::agg_token_value_text | ( | UUID | token | ) |
Recover the "value (*)" display string for an aggregation gate.
Companion helper to the provsql.aggtoken_text_as_uuid GUC. With the GUC on, an AGG_TOKEN cell prints as the underlying provenance UUID, which is convenient for tooling that wants to click through to the circuit but loses the human-readable aggregate value. This function takes such a UUID and returns the original "value (*)" string by reading the gate's extra (set by aggregate evaluation for agg gates, and by agg_arith_make for the arith gates that AGG_TOKEN arithmetic mints). Returns NULL if token does not resolve to an agg or arith gate.
| token | UUID of an agg gate (typically obtained from an AGG_TOKEN cell when aggtoken_text_as_uuid is on, or via a manual UUID cast otherwise). |
| UUID update_provenance::agg_value_gate | ( | NUMERIC | v | ) |
Lift a scalar NUMERIC constant into a gate_value leaf and return its UUID, so it can be a child of a gate_arith (the agg-side analogue of as_random for random_variable).
| CREATE CAST | ( | AGG_TOKEN AS | NUMERIC | ) |
Assignment cast from AGG_TOKEN to NUMERIC (extracts the scalar value, dropping provenance).
Assignment cast from AGG_TOKEN to TEXT (extracts value, not UUID).
Assignment cast from AGG_TOKEN to bigint.
Assignment cast from AGG_TOKEN to INTEGER.
Assignment cast from AGG_TOKEN to DOUBLE PRECISION.
ASSIGNMENT, not IMPLICIT: provenance- preserving arithmetic on aggregates is provided by the native AGG_TOKEN operators below, so an implicit NUMERIC coercion would only silently steal s + 1 away from them (and reroute it differently depending on whether provsql is in search_path). Write s::NUMERIC to opt into the lossy scalar.
| UUID update_provenance::CAST(AGG_TOKEN AS UUID) | ( | AGG_TOKEN | ) |
Implicit PostgreSQL cast from AGG_TOKEN to UUID (delegates to agg_token_uuid()).
| BOOLEAN update_provenance::numeric_comp_agg_token | ( | NUMERIC | a, |
| AGG_TOKEN | b ) |
Placeholder comparison of NUMERIC with AGG_TOKEN.
Symmetric to agg_token_comp_numeric; never actually called. The ProvSQL query rewriter replaces these comparisons at plan time.
| AGG_TOKEN update_provenance::numeric_div_agg_token | ( | NUMERIC | a, |
| AGG_TOKEN | b ) |
NUMERIC / AGG_TOKEN.
| BOOLEAN update_provenance::numeric_eq_agg_token | ( | NUMERIC | left, |
| AGG_TOKEN | right ) |
SQL operator NUMERIC = AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::numeric_ge_agg_token | ( | NUMERIC | left, |
| AGG_TOKEN | right ) |
SQL operator NUMERIC >= AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::numeric_gt_agg_token | ( | NUMERIC | left, |
| AGG_TOKEN | right ) |
SQL operator NUMERIC > AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::numeric_le_agg_token | ( | NUMERIC | left, |
| AGG_TOKEN | right ) |
SQL operator NUMERIC <= AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::numeric_lt_agg_token | ( | NUMERIC | left, |
| AGG_TOKEN | right ) |
SQL operator NUMERIC < AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
| AGG_TOKEN update_provenance::numeric_minus_agg_token | ( | NUMERIC | a, |
| AGG_TOKEN | b ) |
NUMERIC - AGG_TOKEN.
| BOOLEAN update_provenance::numeric_ne_agg_token | ( | NUMERIC | left, |
| AGG_TOKEN | right ) |
SQL operator NUMERIC <> AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN numeric_op_agg_token | ( | NUMERIC | left, |
| AGG_TOKEN | right ) |
| AGG_TOKEN update_provenance::numeric_plus_agg_token | ( | NUMERIC | a, |
| AGG_TOKEN | b ) |
| AGG_TOKEN update_provenance::numeric_times_agg_token | ( | NUMERIC | a, |
| AGG_TOKEN | b ) |
NUMERIC * AGG_TOKEN.
| BOOLEAN update_provenance::text_comp_agg_token | ( | TEXT | a, |
| AGG_TOKEN | b ) |
Placeholder comparison of TEXT with AGG_TOKEN.
Symmetric to agg_token_comp_text; never actually called. The ProvSQL query rewriter replaces these comparisons at plan time.
| BOOLEAN update_provenance::text_eq_agg_token | ( | TEXT | left, |
| AGG_TOKEN | right ) |
SQL operator TEXT = AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
| BOOLEAN update_provenance::text_ne_agg_token | ( | TEXT | left, |
| AGG_TOKEN | right ) |
SQL operator TEXT <> AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).