ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
agg_token.c File Reference

PostgreSQL I/O functions and cast for the agg_token composite type. More...

#include "postgres.h"
#include "fmgr.h"
#include "catalog/pg_type.h"
#include "utils/uuid.h"
#include "utils/numeric.h"
#include "utils/fmgrprotos.h"
#include "executor/spi.h"
#include "access/htup_details.h"
#include "provsql_utils.h"
#include "agg_token.h"
Include dependency graph for agg_token.c:

Go to the source code of this file.

Functions

Datum agg_token_in (PG_FUNCTION_ARGS)
 Parse an agg_token value from its text representation.
Datum agg_token_out (PG_FUNCTION_ARGS)
 Produce a display string for an agg_token.
Datum agg_token_cast (PG_FUNCTION_ARGS)
 Cast an agg_token to text, returning only the UUID part.
Datum agg_token_to_numeric (PG_FUNCTION_ARGS)
 Cast an agg_token to numeric, extracting only the value.
Datum agg_token_to_float8 (PG_FUNCTION_ARGS)
 Cast an agg_token to double precision, extracting only the value.
Datum agg_token_to_int4 (PG_FUNCTION_ARGS)
 Cast an agg_token to integer, extracting only the value.
Datum agg_token_to_int8 (PG_FUNCTION_ARGS)
 Cast an agg_token to bigint, extracting only the value.
Datum agg_token_to_text (PG_FUNCTION_ARGS)
 Cast an agg_token to text, extracting only the value.

Detailed Description

PostgreSQL I/O functions and cast for the agg_token composite type.

Implements the three SQL-callable C functions that back the agg_token type:

The on-wire text format is ( UUID , value ) where UUID is the 36-character hyphenated UUID of the provenance gate and value is the aggregate running value.

Definition in file agg_token.c.

Function Documentation

◆ agg_token_cast()

Datum agg_token_cast ( PG_FUNCTION_ARGS )

Cast an agg_token to text, returning only the UUID part.

This is used when the caller needs the provenance circuit UUID stored in the token rather than the aggregate value.

Returns
Text datum containing the UUID string of the token.

Definition at line 109 of file agg_token.c.

◆ agg_token_in()

Datum agg_token_in ( PG_FUNCTION_ARGS )

Parse an agg_token value from its text representation.

Expected format: "( UUID , value )" with a single space around the comma and at the outer parentheses. Raises ERROR on malformed input.

Returns
Pointer to the newly allocated agg_token.

Definition at line 36 of file agg_token.c.

◆ agg_token_out()

Datum agg_token_out ( PG_FUNCTION_ARGS )

Produce a display string for an agg_token.

Default: returns "value (*)" (the running value followed by " (*)"), matching EXPLAIN and direct CAST to text.

When the provsql.aggtoken_text_as_uuid GUC is on, returns the underlying provenance UUID instead. This is the form ProvSQL Studio enables per session so agg_token cells in a result table expose the circuit root UUID for click-through; the user-facing "value (*)" string is recovered via the provsql.agg_token_value_text(uuid) helper.

Returns
C-string representation of the agg_token.

Definition at line 87 of file agg_token.c.

◆ agg_token_to_float8()

Datum agg_token_to_float8 ( PG_FUNCTION_ARGS )

Cast an agg_token to double precision, extracting only the value.

Emits a WARNING that provenance information is lost during the conversion.

Returns
Float8 datum parsed from the aggregate value string.

Definition at line 157 of file agg_token.c.

◆ agg_token_to_int4()

Datum agg_token_to_int4 ( PG_FUNCTION_ARGS )

Cast an agg_token to integer, extracting only the value.

Emits a WARNING that provenance information is lost during the conversion.

Returns
Int32 datum parsed from the aggregate value string.

Definition at line 177 of file agg_token.c.

◆ agg_token_to_int8()

Datum agg_token_to_int8 ( PG_FUNCTION_ARGS )

Cast an agg_token to bigint, extracting only the value.

Emits a WARNING that provenance information is lost during the conversion.

Returns
Int64 datum parsed from the aggregate value string.

Definition at line 197 of file agg_token.c.

◆ agg_token_to_numeric()

Datum agg_token_to_numeric ( PG_FUNCTION_ARGS )

Cast an agg_token to numeric, extracting only the value.

Emits a WARNING that provenance information is lost during the conversion.

Returns
Numeric datum parsed from the aggregate value string.

Definition at line 135 of file agg_token.c.

◆ agg_token_to_text()

Datum agg_token_to_text ( PG_FUNCTION_ARGS )

Cast an agg_token to text, extracting only the value.

Unlike agg_token_cast which returns the UUID part, this returns the aggregate value as text. Emits a WARNING that provenance information is lost during the conversion.

Returns
Text datum containing the aggregate value string.

Definition at line 219 of file agg_token.c.