Skip to content

PgRange

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Creates and parses typed PostgreSQL ranges without static members on generic types.

public static class PgRange

Inheritance: object

Creates a range with inferred bound type, inclusive lower bound and exclusive upper bound by default.

public static PgRange<T> Create<T>(T lower, T upper, bool lowerInclusive = true, bool upperInclusive = false) where T : struct

Type parameters:

T

The supported bound type.

Parameters:

lower — T

The lower bound.

upper — T

The upper bound.

lowerInclusive — bool

Whether the lower bound is included.

upperInclusive — bool

Whether the upper bound is included.

Returns: PgRange<T>

The uncanonicalized range.

Creates an empty range without backend access.

public static PgRange<T> Empty<T>() where T : struct

Type parameters:

T

The supported bound type.

Returns: PgRange<T>

The empty range.

Resolves a .NET index range against a collection length and returns its half-open PostgreSQL integer interval.

public static PgRange<int> FromRange(Range range, int length)

Parameters:

range — Range

The .NET range, including from-end indices.

length — int

The collection length used to resolve indices.

Returns: PgRange<int>

The integer interval, or empty for a zero-length slice.

Parses and canonicalizes a built-in range using PostgreSQL on the active backend.

public static PgRange<T> Parse<T>(string text) where T : struct

Type parameters:

T

The supported bound type.

Parameters:

text — string

The PostgreSQL range text.

Returns: PgRange<T>

The canonical range.

Tries backend parsing, returning false for malformed bounds or subtype range errors.

public static bool TryParse<T>(string? text, out PgRange<T>? value) where T : struct

Type parameters:

T

The supported bound type.

Parameters:

text — string

The PostgreSQL range text.

value — PgRange<T>

The canonical range, or null.

Returns: bool

Whether parsing succeeded.

For built-in range types, invalid input leaves no error pending: PostgreSQL 16 and later report it as a soft input error, and earlier majors roll back an internal subtransaction. Before PostgreSQL 16, transaction callbacks and parallel operations forbid that rollback; native errors there remain pending and throw PgException.

Creates a fully unbounded range, distinct from empty and from SQL NULL.

public static PgRange<T> Unbounded<T>() where T : struct

Type parameters:

T

The supported bound type.

Returns: PgRange<T>

The unbounded range.