Skip to content

PgArray<T>

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Owns a row-major PostgreSQL array, preserving up to six dimensions and their lower bounds. Use nullable value types for SQL NULL elements and nullable annotations for reference elements. A null array reference represents SQL NULL.

public sealed class PgArray<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Type parameters:

T

A supported scalar element type, such as int?, string, PgNumeric, or a registered datum mapping.

Inheritance: object

Implements: IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Copies a vector. Nonempty vectors have one dimension with lower bound one.

public PgArray(IEnumerable<T> values)

Parameters:

values — IEnumerable<T>

The elements in order.

PgArray(ReadOnlySpan<T>, ReadOnlySpan<int>, ReadOnlySpan<int>)

Section titled “PgArray(ReadOnlySpan<T>, ReadOnlySpan<int>, ReadOnlySpan<int>)”

Copies elements and dimensions. Empty arrays normalize to PostgreSQL’s zero-dimensional empty array.

public PgArray(ReadOnlySpan<T> values, ReadOnlySpan<int> lengths, ReadOnlySpan<int> lowerBounds = default)

Parameters:

values — ReadOnlySpan<T>

The row-major elements; the last subscript varies fastest.

lengths — ReadOnlySpan<int>

Zero through six dimension lengths whose product equals the element count.

lowerBounds — ReadOnlySpan<int>

One lower bound per dimension, or an empty span to use one for every dimension.

Gets the total element count, including SQL NULL elements.

public int Count { get; }

Value: int

Gets the PostgreSQL element identity, including the named composite identity of an empty or all-null array. Enum, custom type and registered datum identities are resolved in the current backend when requested.

public uint ElementTypeOid { get; }

Value: uint

Gets an element by its zero-based flat index, independently of PostgreSQL lower bounds.

public T this[int index] { get; }

Parameters:

index — int

The row-major index.

Value: T

The element.

Gets the dimension lengths without exposing mutable storage.

public ReadOnlySpan<int> Lengths { get; }

Value: ReadOnlySpan<int>

Gets the PostgreSQL lower bounds without exposing mutable storage.

public ReadOnlySpan<int> LowerBounds { get; }

Value: ReadOnlySpan<int>

Gets the number of dimensions. PostgreSQL empty arrays have rank zero.

public int Rank { get; }

Value: int

Enumerates elements in row-major order.

public IEnumerator<T> GetEnumerator()

Returns: IEnumerator<T>

The enumerator.

Gets an element by PostgreSQL subscripts, including negative and non-one lower bounds.

public T GetValue(params ReadOnlySpan<int> subscripts)

Parameters:

subscripts — ReadOnlySpan<int>

Exactly one subscript per dimension.

Returns: T

The element.

Copies all elements in row-major order, explicitly discarding shape and lower bounds.

public T[] ToArray()

Returns: T[]

A flat managed array.

Copies a zero- or one-dimensional array with lower bound one, rejecting shape loss.

public T[] ToVector()

Returns: T[]

The managed vector.