ProvSQL SQL API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
provsql.sql File Reference

ProvSQL PL/pgSQL extension code. More...

Go to the source code of this file.

Types

TYPE  provsql.GATE_WITH_DESC
 Row type for sub_circuit_with_desc results. More...
TYPE  provsql.update_provenance
 Table recording the history of INSERT, UPDATE, DELETE, and UNDO operations. More...

Schemas

namespace  provsql
 provsql schema

Enumerations

ENUM  provsql.PROVENANCE_GATE {
  provsql.input , provsql.plus , provsql.times , provsql.monus ,
  provsql.project , provsql.zero , provsql.one , provsql.eq ,
  provsql.agg , provsql.semimod , provsql.cmp , provsql.delta ,
  provsql.value , provsql.mulinput , provsql.update , provsql.rv ,
  provsql.arith , provsql.mixture , provsql.assumed_boolean
}
 Provenance circuit gate types. More...
ENUM  provsql.QUERY_TYPE_ENUM { provsql.INSERT , provsql.DELETE , provsql.UPDATE , provsql.UNDO }
 Types of update operations tracked for temporal provenance. More...

Functions

VOID provsql.create_gate (UUID token, PROVENANCE_GATE type, UUID[] children=NULL)
 Create a new gate in the provenance circuit.
PROVENANCE_GATE provsql.get_gate_type (UUID token)
 Return the gate type of a provenance token.
UUID[] provsql.get_children (UUID token)
 Return the children of a provenance gate.
VOID provsql.set_prob (UUID token, DOUBLE PRECISION p)
 Set the probability of an input gate.
DOUBLE PRECISION provsql.get_prob (UUID token)
 Get the probability associated with an input gate.
VOID provsql.set_infos (UUID token, INT info1, INT info2=NULL)
 Set additional INTEGER values on provenance circuit gate.
RECORD provsql.get_infos (UUID token, OUT INT info1, OUT INT info2)
 Get the INTEGER info values associated with a circuit gate.
UUID provsql.assume_boolean (UUID token)
 Wrap token in a fresh gate_assumed_boolean and return the wrapper's UUID.
VOID provsql.set_extra (UUID token, TEXT data)
 Set extra TEXT information on provenance circuit gate.
TEXT provsql.get_extra (UUID token)
 Get the TEXT-encoded extra data associated with a circuit gate.
BIGINT provsql.get_nb_gates ()
 Return the total number of materialized gates in the provenance circuit.
TRIGGER provsql.delete_statement_trigger ()
 Trigger function for DELETE statement provenance tracking.
VOID provsql.set_table_info (OID relid, TEXT kind, INT2[] block_key=ARRAY[]::INT2[])
 Record per-relation provenance metadata used by the safe-query optimisation.
VOID provsql.remove_table_info (OID relid)
 Remove per-relation provenance metadata.
RECORD provsql.get_table_info (OID relid, OUT TEXT kind, INT2[] &block_key)
 Read per-relation provenance metadata.
VOID provsql.set_ancestors (OID relid, OID[] ancestors=ARRAY[]::OID[])
 Record the base-relation ancestor set of a tracked relation.
VOID provsql.remove_ancestors (OID relid)
 Clear the ancestor half of a per-relation RECORD (keeps kind/block_key).
OID[] provsql.get_ancestors (OID relid)
 Read the base-relation ancestor set of a tracked relation.
TRIGGER provsql.provenance_guard ()
 BEFORE INSERT OR UPDATE OF provsql row trigger installed by add_provenance.
VOID provsql.add_provenance (REGCLASS _tbl)
 Enable provenance tracking on an existing table.
VOID provsql.remove_provenance (REGCLASS _tbl)
 Remove provenance tracking from a table.
VOID provsql.repair_key (REGCLASS _tbl, TEXT key_att)
 Set up provenance for a table with duplicate key values.
event_trigger provsql.cleanup_table_info ()
 Event trigger that purges per-table provenance metadata when a tracked relation is dropped outside of remove_provenance().
VOID provsql.create_provenance_mapping (TEXT newtbl, REGCLASS oldtbl, TEXT att, BOOL preserve_case='f')
 Create a provenance mapping table from an attribute.
VOID provsql.create_provenance_mapping_view (TEXT newview, REGCLASS oldtbl, TEXT att, BOOL preserve_case=false)
 Create a view mapping provenance tokens to attribute values.
UUID provsql.uuid_ns_provsql ()
 Return the ProvSQL UUID namespace (used for deterministic gate UUIDs).
UUID provsql.gate_zero ()
 Return the UUID of the semiring zero gate.
UUID provsql.gate_one ()
 Return the UUID of the semiring one gate.
DOUBLE PRECISION provsql.epsilon ()
 Return the epsilon threshold used for probability comparisons.
UUID provsql.provenance_times (UUID[] tokens)
 Create a times (product) gate from multiple provenance tokens.
UUID provsql.provenance_monus (UUID token1, UUID token2)
 Create a monus (difference) gate from two provenance tokens.
UUID provsql.provenance_project (UUID token, INT[] positions)
 Create a project gate for where-provenance tracking.
UUID provsql.provenance_eq (UUID token, INT pos1, INT pos2)
 Create an equijoin gate for where-provenance tracking.
UUID provsql.provenance_plus (UUID[] tokens)
 Create a plus (sum) gate from an array of provenance tokens.
UUID provsql.provenance_cmp (UUID left_token, OID comparison_op, UUID right_token)
 Create a comparison gate for HAVING clause provenance.
UUID provsql.provenance_arith (INTEGER op, UUID[] children)
 Create an arithmetic gate over scalar-valued provenance children.
ANYELEMENT provsql.provenance_evaluate_compiled (UUID token, REGCLASS token2value, TEXT semiring, ANYELEMENT element_one)
 Evaluate provenance using a compiled (built-in) semiring.
ANYELEMENT provsql.provenance_evaluate (UUID token, REGCLASS token2value, ANYELEMENT element_one, REGTYPE value_type, REGPROC plus_function, REGPROC times_function, REGPROC monus_function, REGPROC delta_function)
 Evaluate provenance over a user-defined semiring (PL/pgSQL version).
ANYELEMENT provsql.aggregation_evaluate (UUID token, REGCLASS token2value, REGPROC agg_function_final, REGPROC agg_function, REGPROC semimod_function, ANYELEMENT element_one, REGTYPE value_type, REGPROC plus_function, REGPROC times_function, REGPROC monus_function, REGPROC delta_function)
 Evaluate aggregate provenance over a user-defined semiring (PL/pgSQL version).
ANYELEMENT provsql.provenance_evaluate (UUID token, REGCLASS token2value, ANYELEMENT element_one, REGPROC plus_function, REGPROC times_function, REGPROC monus_function=NULL, REGPROC delta_function=NULL)
 Evaluate provenance over a user-defined semiring (C version).
ANYELEMENT provsql.aggregation_evaluate (UUID token, REGCLASS token2value, REGPROC agg_function_final, REGPROC agg_function, REGPROC semimod_function, ANYELEMENT element_one, REGPROC plus_function, REGPROC times_function, REGPROC monus_function=NULL, REGPROC delta_function=NULL)
 Evaluate aggregate provenance over a user-defined semiring (C version).
SETOF GATE_WITH_DESC provsql.sub_circuit_with_desc (UUID token, REGCLASS token2desc)
 Return the sub-circuit reachable from a token, with descriptions.
VOID provsql.identify_token (UUID token, OUT REGCLASS table_name, OUT INTEGER nb_columns)
 Identify which table and how many columns a provenance token belongs to.
TABLE provsql.sub_circuit_for_where (UUID token)
 Return the sub-circuit for where-provenance computation.
TABLE provsql.circuit_subgraph (UUID root, INT max_depth=8)
 BFS expansion of a provenance circuit, capped at max_depth.
jsonb provsql.simplified_circuit_subgraph (UUID root, INT max_depth=8)
 BFS subgraph of the IN-MEMORY simplified circuit rooted at root.
jsonb provsql.rv_histogram (UUID token, INT bins=30, UUID prov=gate_one())
 Empirical histogram of a scalar sub-circuit.
jsonb provsql.rv_analytical_curves (UUID token, INT samples=100, UUID prov=gate_one())
 Sample the closed-form PDF and CDF of a (possibly truncated) scalar distribution.
SETOF float8 provsql.rv_sample (UUID token, INTEGER n, UUID prov=gate_one())
 Draw conditional Monte Carlo samples from a scalar gate.
TABLE provsql.resolve_input (UUID UUID)
 Resolve an input gate UUID back to its source row.
AGG_TOKEN provsql.agg_token_in (CSTRING)
 Input function for the AGG_TOKEN type (parses TEXT representation).
CSTRING provsql.agg_token_out (AGG_TOKEN)
 Output function for the AGG_TOKEN type.
TEXT provsql.agg_token_cast (AGG_TOKEN)
 Cast an AGG_TOKEN to its TEXT representation.
UUID provsql.agg_token_uuid (AGG_TOKEN aggtok)
 Extract the UUID from an AGG_TOKEN (implicit cast to UUID).
UUID provsql.CAST(AGG_TOKEN AS UUID) (AGG_TOKEN)
 Implicit PostgreSQL cast from AGG_TOKEN to UUID (delegates to agg_token_uuid()).
TEXT provsql.agg_token_value_text (UUID token)
 Recover the "value (*)" display string for an aggregation gate.
NUMERIC provsql.agg_token_to_numeric (AGG_TOKEN)
 Cast an AGG_TOKEN to NUMERIC (extracts the aggregate value, loses provenance).
DOUBLE PRECISION provsql.agg_token_to_float8 (AGG_TOKEN)
 Cast an AGG_TOKEN to DOUBLE PRECISION (extracts the aggregate value, loses provenance).
INTEGER provsql.agg_token_to_int4 (AGG_TOKEN)
 Cast an AGG_TOKEN to INTEGER (extracts the aggregate value, loses provenance).
bigint provsql.agg_token_to_int8 (AGG_TOKEN)
 Cast an AGG_TOKEN to bigint (extracts the aggregate value, loses provenance).
TEXT provsql.agg_token_to_text (AGG_TOKEN)
 Cast an AGG_TOKEN to TEXT (extracts the aggregate value, loses provenance).
NUMERIC provsql.CAST(AGG_TOKEN AS NUMERIC) (AGG_TOKEN)
 Implicit PostgreSQL cast from AGG_TOKEN to NUMERIC (enables arithmetic on aggregates).
CREATE provsql.CAST (AGG_TOKEN AS DOUBLE PRECISION) WITH FUNCTION agg_token_to_float8(AGG_TOKEN) AS ASSIGNMENT
 Assignment cast from AGG_TOKEN to DOUBLE PRECISION.
BOOLEAN provsql.agg_token_comp_numeric (AGG_TOKEN a, NUMERIC b)
 Placeholder comparison of AGG_TOKEN with NUMERIC.
BOOLEAN provsql.numeric_comp_agg_token (NUMERIC a, AGG_TOKEN b)
 Placeholder comparison of NUMERIC with AGG_TOKEN.
BOOLEAN provsql.agg_token_lt_numeric (AGG_TOKEN left, NUMERIC right)
 SQL operator AGG_TOKEN < NUMERIC (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.numeric_lt_agg_token (NUMERIC left, AGG_TOKEN right)
 SQL operator NUMERIC < AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.agg_token_le_numeric (AGG_TOKEN left, NUMERIC right)
 SQL operator AGG_TOKEN <= NUMERIC (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.numeric_le_agg_token (NUMERIC left, AGG_TOKEN right)
 SQL operator NUMERIC <= AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.agg_token_eq_numeric (AGG_TOKEN left, NUMERIC right)
 SQL operator AGG_TOKEN = NUMERIC (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.numeric_eq_agg_token (NUMERIC left, AGG_TOKEN right)
 SQL operator NUMERIC = AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.agg_token_ne_numeric (AGG_TOKEN left, NUMERIC right)
 SQL operator AGG_TOKEN <> NUMERIC (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.numeric_ne_agg_token (NUMERIC left, AGG_TOKEN right)
 SQL operator NUMERIC <> AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.agg_token_ge_numeric (AGG_TOKEN left, NUMERIC right)
 SQL operator AGG_TOKEN >= NUMERIC (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.numeric_ge_agg_token (NUMERIC left, AGG_TOKEN right)
 SQL operator NUMERIC >= AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.agg_token_gt_numeric (AGG_TOKEN left, NUMERIC right)
 SQL operator AGG_TOKEN > NUMERIC (placeholder rewritten by ProvSQL at plan time).
BOOLEAN provsql.numeric_gt_agg_token (NUMERIC left, AGG_TOKEN right)
 SQL operator NUMERIC > AGG_TOKEN (placeholder rewritten by ProvSQL at plan time).
random_variable provsql.random_variable_in (CSTRING)
 Input function for the random_variable type.
CSTRING provsql.random_variable_out (random_variable)
 Output function for the random_variable type.
random_variable provsql.random_variable_make (UUID tok)
 Build a random_variable from a UUID (internal).
CREATE provsql.CAST (random_variable AS UUID) WITHOUT FUNCTION AS IMPLICIT
 Binary-coercible cast random_variable -> UUID.
CREATE provsql.CAST (UUID AS random_variable) WITHOUT FUNCTION
BOOL provsql.is_finite_float8 (DOUBLE PRECISION x)
 Internal: true iff x is a finite (non-NaN, non-±∞) float8.
random_variable provsql.normal (DOUBLE PRECISION mu, DOUBLE PRECISION sigma)
 Construct a normal-distribution random variable.
random_variable provsql.uniform (DOUBLE PRECISION a, DOUBLE PRECISION b)
 Construct a uniform-distribution random variable on [a, b].
random_variable provsql.exponential (DOUBLE PRECISION lambda)
 Construct an exponential-distribution random variable with rate λ
random_variable provsql.erlang (INTEGER k, DOUBLE PRECISION lambda)
 Construct an Erlang-distribution random variable, sum of k i.i.d.
random_variable provsql.mixture (UUID p, random_variable x, random_variable y)
 Construct a probabilistic-mixture random variable.
random_variable provsql.mixture (DOUBLE PRECISION p_value, random_variable x, random_variable y)
 Ad-hoc mixture constructor that mints a fresh anonymous gate_input Bernoulli with probability p_value.
random_variable provsql.categorical (DOUBLE_PRECISION[] probs, DOUBLE_PRECISION[] outcomes)
 Categorical-RV constructor over explicit (probabilities, values) arrays.
random_variable provsql.as_random (DOUBLE PRECISION c)
 Lift a deterministic constant into a random_variable.
CREATE provsql.CAST (DOUBLE PRECISION AS random_variable) WITH FUNCTION as_random(DOUBLE PRECISION) AS IMPLICIT
 Implicit cast DOUBLE PRECISION -> random_variable (lifts a scalar literal to a constant RV).
random_variable provsql.as_random (INTEGER c)
 as_random for INTEGER (delegates to the float8 form).
random_variable provsql.as_random (NUMERIC c)
 as_random for NUMERIC (delegates to the float8 form).
random_variable provsql.CAST(INTEGER AS RANDOM_VARIABLE) (INTEGER)
 Implicit cast INTEGER -> random_variable.
random_variable provsql.CAST(NUMERIC AS RANDOM_VARIABLE) (NUMERIC)
 Implicit cast NUMERIC -> random_variable.
UUID provsql.provenance_delta (UUID token)
 Create a δ-semiring gate wrapping a provenance token.
AGG_TOKEN provsql.provenance_aggregate (INTEGER aggfnoid, INTEGER aggtype, ANYELEMENT val, UUID[] tokens)
 Build an aggregate provenance gate from grouped tokens.
UUID provsql.provenance_semimod (ANYELEMENT val, UUID token)
 Create a semimodule scalar multiplication gate.
DOUBLE PRECISION provsql.probability_evaluate (UUID token, TEXT method=NULL, TEXT arguments=NULL)
 Compute the probability of a provenance token.
DOUBLE PRECISION provsql.expected (ANYELEMENT input, UUID prov=gate_one(), TEXT method=NULL, TEXT arguments=NULL)
 Compute the expected value of a probabilistic scalar.
DOUBLE PRECISION provsql.rv_moment (UUID token, INTEGER k, BOOLEAN central, UUID prov=gate_one())
 Internal: shared C entry point for variance / moment / central_moment.
DOUBLE PRECISION provsql.agg_raw_moment (AGG_TOKEN token, INTEGER k, UUID prov=gate_one(), TEXT method=NULL, TEXT arguments=NULL)
 Compute the raw moment E[X^k | prov] of an AGG_TOKEN aggregate.
DOUBLE PRECISION provsql.variance (ANYELEMENT input, UUID prov=gate_one(), TEXT method=NULL, TEXT arguments=NULL)
 Compute the variance Var[X | prov] of a probabilistic scalar.
DOUBLE PRECISION provsql.moment (ANYELEMENT input, INTEGER k, UUID prov=gate_one(), TEXT method=NULL, TEXT arguments=NULL)
 Compute the raw moment E[X^k | prov] of a probabilistic scalar.
VOID provsql.rv_support (UUID token, UUID prov=gate_one(), float8 &lo, float8 &hi)
 Internal: rv-side support computation.
VOID provsql.support (ANYELEMENT input, UUID prov=gate_one(), TEXT method=NULL, TEXT arguments=NULL, float8 &lo, float8 &hi)
 Compute the support interval [lo, hi] of a probabilistic (or deterministic) scalar.
DOUBLE PRECISION provsql.central_moment (ANYELEMENT input, INTEGER k, UUID prov=gate_one(), TEXT method=NULL, TEXT arguments=NULL)
 Compute the central moment E[(X - E[X|prov])^k | prov].
DOUBLE PRECISION provsql.shapley (UUID token, UUID variable, TEXT method=NULL, TEXT arguments=NULL, BOOLEAN banzhaf='f')
 Compute the Shapley value of an input variable.
SETOF RECORD provsql.shapley_all_vars (UUID token, TEXT method=NULL, TEXT arguments=NULL, BOOLEAN banzhaf='f', OUT UUID variable, OUT DOUBLE PRECISIONvalue)
 Compute Shapley values for all input variables at once.
DOUBLE PRECISION provsql.banzhaf (UUID token, UUID variable, TEXT method=NULL, TEXT arguments=NULL)
 Compute the Banzhaf power index of an input variable.
SETOF RECORD provsql.banzhaf_all_vars (UUID token, TEXT method=NULL, TEXT arguments=NULL, OUT UUID variable, OUT DOUBLE PRECISIONvalue)
 Compute Banzhaf power indices for all input variables at once.
TEXT provsql.view_circuit (UUID token, REGCLASS token2desc, INT dbg=0)
 Return a DOT or TEXT visualization of the provenance circuit.
TEXT provsql.to_provxml (UUID token, REGCLASS token2desc=NULL)
 Return an XML representation of the provenance circuit.
UUID provsql.provenance ()
 Return the provenance token of the current query result tuple.
TEXT provsql.where_provenance (UUID token)
 Compute where-provenance for a result tuple.
VOID provsql.reset_constants_cache ()
 Reset the internal cache of OID constants used by the query rewriter.
VARCHAR provsql.sr_formula (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance as a symbolic formula (e.g., "a ⊗ b ⊕ c").
INT provsql.sr_counting (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the counting semiring (ℕ).
VARCHAR provsql.sr_why (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance as why-provenance (set of witness sets).
VARCHAR provsql.sr_how (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance as how-provenance (canonical polynomial provenance ℕ[X], universal commutative-semiring provenance).
VARCHAR provsql.sr_which (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance as which-provenance (lineage: a single set of contributing labels).
VARCHAR provsql.sr_boolexpr (ANYELEMENT token, REGCLASS token2value=NULL)
 Evaluate provenance as a Boolean expression.
BOOLEAN provsql.sr_boolean (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the Boolean semiring (true/false).
FLOAT provsql.sr_tropical (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the tropical (min-plus) m-semiring.
FLOAT provsql.sr_viterbi (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the Viterbi (max-times) m-semiring.
FLOAT provsql.sr_lukasiewicz (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the Łukasiewicz fuzzy m-semiring.
ANYENUM provsql.sr_minmax (UUID token, REGCLASS token2value, ANYENUM element_one)
 Evaluate provenance over the min-max m-semiring on a user ENUM.
ANYENUM provsql.sr_maxmin (UUID token, REGCLASS token2value, ANYENUM element_one)
 Evaluate provenance over the max-min m-semiring on a user ENUM.
ANYELEMENT provsql.choose_function (ANYELEMENT state, ANYELEMENT data)
 Transition function for the choose aggregate (keeps first non-NULL value).
VOID provsql.choose (ANYELEMENT)
 Aggregate that returns an arbitrary non-NULL value from a group.
TRIGGER provsql.insert_statement_trigger ()
 Trigger function for INSERT statement provenance tracking.
TRIGGER provsql.update_statement_trigger ()
 Trigger function for UPDATE statement provenance tracking.
TSTZMULTIRANGE provsql.sr_temporal (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the temporal (interval-union) m-semiring.
nummultirange provsql.sr_interval_num (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the interval-union m-semiring with a NUMERIC multirange carrier.
int4multirange provsql.sr_interval_int (ANYELEMENT token, REGCLASS token2value)
 Evaluate provenance over the interval-union m-semiring with an int4 multirange carrier.
TSTZMULTIRANGE provsql.union_tstzintervals (UUID token, REGCLASS token2value)
 Evaluate temporal provenance as a TIMESTAMP multirange.
SETOF RECORD provsql.timetravel (TEXT tablename, TIMESTAMPTZ at_time)
 Query a table as it was at a specific point in time.
SETOF RECORD provsql.timeslice (TEXT tablename, TIMESTAMPTZ from_time, TIMESTAMPTZ to_time)
 Query a table for rows valid during a time interval.
SETOF RECORD provsql.history (TEXT tablename, TEXT[] col_names, TEXT[] col_values)
 Query the full temporal history of specific rows.
TSTZMULTIRANGE provsql.get_valid_time (UUID token, TEXT tablename)
 Get the valid time range for a specific tuple.
UUID provsql.undo (UUID c)
 Undo a previously recorded update operation.
UUID provsql.replace_the_circuit (UUID x, UUID c, UUID u)
 Recursively rewrite a circuit to undo a specific operation.
Arithmetic and comparison on random_variable

Each binary operator below is declared on (random_variable, random_variable) only; mixed shapes such as rv + 2 or 2.5 > rv resolve through the implicit casts from INTEGER / NUMERIC / double precision to random_variable declared above.

This avoids the resolution ambiguity that would arise if both (rv, NUMERIC) and (rv, rv) overloads were declared while implicit casts also existed.

Arithmetic operators build a gate_arith via provenance_arith and return a new random_variable wrapping its UUID.

Comparison operators are placeholders that return BOOLEAN and raise if executed – the BOOLEAN return type is required so that PostgreSQL accepts WHERE rv > 2 at parse-analyze. The planner hook intercepts every such OpExpr (matched by opfuncid against constants_t::OID_FUNCTION_RV_CMP) and rewrites it into a provenance_cmp call whose UUID is conjoined into the tuple's provsql column via provenance_times. Code that needs a gate_cmp UUID directly (without going through the planner hook) uses the rv_cmp_* family below, which call provenance_cmp with the matching float8-comparator OID.

random_variable provsql.random_variable_plus (random_variable a, random_variable b)
 random_variable + random_variable (gate_arith PLUS).
random_variable provsql.random_variable_minus (random_variable a, random_variable b)
 random_variable - random_variable (gate_arith MINUS).
random_variable provsql.random_variable_times (random_variable a, random_variable b)
 random_variable * random_variable (gate_arith TIMES).
random_variable provsql.random_variable_div (random_variable a, random_variable b)
 random_variable / random_variable (gate_arith DIV).
random_variable provsql.random_variable_neg (random_variable a)
 Unary -random_variable (gate_arith NEG).
oid provsql.random_variable_cmp_oid (TEXT sym)
 Internal helper: float8-comparator OID for a given symbol.
BOOLEAN provsql.random_variable_cmp_placeholder (random_variable a, random_variable b)
 Placeholder body shared by every random_variable_* comparison procedure.
BOOLEAN provsql.random_variable_lt (random_variable a, random_variable b)
BOOLEAN provsql.random_variable_le (random_variable a, random_variable b)
BOOLEAN provsql.random_variable_eq (random_variable a, random_variable b)
BOOLEAN provsql.random_variable_ne (random_variable a, random_variable b)
BOOLEAN provsql.random_variable_ge (random_variable a, random_variable b)
BOOLEAN provsql.random_variable_gt (random_variable a, random_variable b)
UUID provsql.rv_cmp_lt (random_variable a, random_variable b)
UUID provsql.rv_cmp_le (random_variable a, random_variable b)
 Build a gate_cmp for a ≤ b and return its UUID.
UUID provsql.rv_cmp_eq (random_variable a, random_variable b)
 Build a gate_cmp for a = b and return its UUID.
UUID provsql.rv_cmp_ne (random_variable a, random_variable b)
 Build a gate_cmp for a <> b and return its UUID.
UUID provsql.rv_cmp_ge (random_variable a, random_variable b)
 Build a gate_cmp for a ≥ b and return its UUID.
UUID provsql.rv_cmp_gt (random_variable a, random_variable b)
 Build a gate_cmp for a > b and return its UUID.
BOOLEAN provsql.random_variable_op_random_variable (random_variable left, random_variable right)
BOOLEAN provsql.random_variable_lt_random_variable (random_variable left, random_variable right)
 Prefix unary minus on random_variable.
BOOLEAN provsql.random_variable_le_random_variable (random_variable left, random_variable right)
BOOLEAN provsql.random_variable_eq_random_variable (random_variable left, random_variable right)
BOOLEAN provsql.random_variable_ne_random_variable (random_variable left, random_variable right)
BOOLEAN provsql.random_variable_ge_random_variable (random_variable left, random_variable right)
BOOLEAN provsql.random_variable_gt_random_variable (random_variable left, random_variable right)
Aggregates over random_variable

Phase 1 of the SUM-over-RV story: an overload of the standard sum aggregate that takes a random_variable per row and returns the random_variable representing the (provenance-weighted) sum.

Lives in the provsql schema so a sum(random_variable) call resolves to it without colliding with the built-in NUMERIC sum overloads in pg_catalog.

Direct calls outside a provenance-tracked query treat each row's contribution unconditionally (no per-row Boolean selector). When the planner hook sees a provsql.sum Aggref over a provenance-tracked query, it wraps the per-row argument x in provsql.mixture(prov_token, x, provsql.as_random(0)) so the aggregate's effective semantics become \(\mathrm{SUM}(x) = \sum_i \mathbf{1}\{\varphi_i\} \cdot X_i\), the natural extension of semimodule-provenance to RV-valued M.

The internal state is the array of UUIDs of the per-row mixtures. The final function builds a single gate_arith PLUS over them (or returns as_random(0) for an empty group, the additive identity). Sharing on provenance_arith's v5 hash means two sum invocations over the same set of rows collide on the same gate.

random_variable provsql.rv_aggregate_semimod (UUID prov, random_variable rv)
 Per-row helper: wrap an RV in mixture(prov, rv, as_random(0)).
UUID[] provsql.sum_rv_sfunc (UUID[] state, random_variable rv)
 State-transition function for sum(random_variable).
random_variable provsql.sum_rv_ffunc (UUID[] state)
 Final function for sum(random_variable): build a gate_arith PLUS root.
VOID provsql.sum (random_variable)
random_variable provsql.avg_rv_ffunc (UUID[] state)
 Final function for avg(random_variable).
VOID provsql.avg (random_variable)
random_variable provsql.product_rv_ffunc (UUID[] state)
 Final function for product(random_variable).
VOID provsql.product (random_variable)

Variables

DROP EVENT TRIGGER IF EXISTS provsql.provsql_cleanup_table_info

Detailed Description

ProvSQL PL/pgSQL extension code.

This file contains the PL/pgSQL code of the ProvSQL extension. This extension requires the standard UUID-ossp extension.

Definition in file provsql.sql.