Skip to content

PgFunctionContext

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Describes the PostgreSQL function call and provides checked raw copies of its SQL arguments.

public sealed class PgFunctionContext

Declare this type as a function parameter to receive it without adding a SQL argument. Metadata is an independent managed snapshot. Argument storage belongs to the scalar callback’s memory context or the set function’s multi-call context. Copy an argument to another context when it needs a longer lifetime. Native argument access requires the owning backend thread.

Inheritance: object

Gets the SQL arguments by zero-based ordinal, excluding injected managed parameters. Every value retains its actual type OID and SQL NULL flag.

public IReadOnlyList<PgDatum> Arguments { get; }

Value: IReadOnlyList<PgDatum>

Gets the collation selected for this call, or zero when no collation applies.

public uint CollationOid { get; }

Value: uint

Gets the catalog OID of the PostgreSQL function being invoked.

public uint FunctionOid { get; }

Value: uint

Gets the resolved PostgreSQL result type OID, including domains and record results.

public uint ResultTypeOid { get; }

Value: uint

Gets the borrowed PostgreSQL context that owns this call site’s cached state.

public PgMemoryContext StateMemoryContext { get; }

Value: PgMemoryContext

Use this context for native allocations retained by cached state. It can outlive individual arguments and iterator instances. Access requires the owning backend thread and a live owner.

Returns this call site’s cached state, creating it once after the first successful factory call.

public T GetOrCreateState<T>(Func<T> factory)

Type parameters:

T

The exact managed state type used consistently at this call site.

Parameters:

factory — Func<T>

The synchronous factory, invoked only when no successful value has been cached.

Returns: T

The cached value, including null when the factory returns null.

Different PostgreSQL call sites have independent state, even when they invoke the same SQL function. Factory failures permit a later retry; recursive initialization of the same site is rejected. PostgreSQL reset or deletion releases the cached value and calls IDisposable.Dispose when implemented. State lookup requires the owning backend thread. Do not use a disposed state after its owner ends.