Skip to content

PgRange<T>

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Owns the bounds of a built-in or explicitly mapped PostgreSQL range. A null reference is SQL NULL; a parameterless instance is empty. Construction retains the requested bounds. PostgreSQL validates and canonicalizes them on datum conversion.

public sealed class PgRange<T> : IEquatable<PgRange<T>> where T : struct

Type parameters:

T

A supported built-in bound or a closed value type declaring both PgDatumType and PgRangeType.

Inheritance: object

Implements: IEquatable<PgRange<T>>

Creates an empty range of the supported bound type.

public PgRange()

Creates a bounded or unbounded range without backend access. Null bounds mean unbounded ends.

public PgRange(T? lower, T? upper, bool lowerInclusive = true, bool upperInclusive = false)

Parameters:

lower — T?

The lower value, or null for an unbounded end.

upper — T?

The upper value, or null for an unbounded end.

lowerInclusive — bool

Whether the lower value is included; ignored when unbounded.

upperInclusive — bool

Whether the upper value is included; ignored when unbounded.

Validates and canonicalizes the bounds using PostgreSQL on the active backend.

public PgRange<T> Canonicalize()

Returns: PgRange<T>

The canonical range, which can be empty even when this instance is not.

Tests whether this range contains another range on the active backend.

public bool Contains(PgRange<T> other)

Parameters:

other — PgRange<T>

The candidate range.

Returns: bool

Whether it is contained.

Tests value containment using PostgreSQL’s subtype ordering and canonical range semantics.

public bool Contains(T value)

Parameters:

value — T

The candidate value.

Returns: bool

Whether the range contains the value.

Compares stored bounds and inclusion flags without backend access or canonicalization.

public bool Equals(PgRange<T>? other)

Parameters:

other — PgRange<T>

The other range.

Returns: bool

Whether their stored representations are equal.

public override bool Equals(object? obj)

Parameters:

obj — object

Returns: bool

Subtracts a range. PostgreSQL raises an error if the result would require two separate ranges.

public PgRange<T> Except(PgRange<T> other)

Parameters:

other — PgRange<T>

The range to subtract.

Returns: PgRange<T>

The canonical difference.

public override int GetHashCode()

Returns: int

Intersects two ranges on the active backend.

public PgRange<T> Intersect(PgRange<T> other)

Parameters:

other — PgRange<T>

The other range.

Returns: PgRange<T>

The intersection, possibly empty.

Tests whether two ranges are adjacent on the active backend.

public bool IsAdjacentTo(PgRange<T> other)

Parameters:

other — PgRange<T>

The other range.

Returns: bool

Whether the ranges are adjacent.

Returns the smallest range spanning both operands, including any gap between them.

public PgRange<T> Merge(PgRange<T> other)

Parameters:

other — PgRange<T>

The other range.

Returns: PgRange<T>

The spanning range.

Tests whether two ranges overlap on the active backend.

public bool Overlaps(PgRange<T> other)

Parameters:

other — PgRange<T>

The other range.

Returns: bool

Whether the ranges overlap.

Formats the canonical range using PostgreSQL on the active backend, including session temporal settings.

public string ToPostgresString()

Returns: string

The PostgreSQL range text.

Describes the stored bounds without backend access or canonicalization. Use ToPostgresString for SQL input text.

public override string ToString()

Returns: string

A diagnostic representation using the bound types’ formatting.

Unites overlapping or adjacent ranges. PostgreSQL raises an error if the result would be disjoint.

public PgRange<T> Union(PgRange<T> other)

Parameters:

other — PgRange<T>

The other range.

Returns: PgRange<T>

The canonical union.

Gets whether this value represents an empty range rather than an interval with bounds.

public bool IsEmpty { get; }

Value: bool

Gets whether the nonempty range has no lower or upper bound.

public bool IsUnbounded { get; }

Value: bool

Gets the lower bound, or null for an empty range or unbounded lower end.

public T? Lower { get; }

Value: T?

Gets whether the present lower bound is included, including an explicit subtype infinity value.

public bool LowerInclusive { get; }

Value: bool

Gets the upper bound, or null for an empty range or unbounded upper end.

public T? Upper { get; }

Value: T?

Gets whether the present upper bound is included, including an explicit subtype infinity value.

public bool UpperInclusive { get; }

Value: bool