decodeArray method

dynamic decodeArray(
  1. String value,
  2. int pgType, {
  3. String? connectionName,
})

Decodes an array value, value, into a flat List. Each item is decoded as pgType.

Limitations (only single-dimension, default-bound arrays are handled):

  • Multidimensional arrays (e.g. {{1,2},{3,4}}) are not supported — they yield garbage or throw FormatException.
  • Arrays with a non-default lower bound carry a dimension prefix (e.g. [0:1]={5,6}), which is not supported.

If you need either, cast the column to text in your query and parse it yourself.

Implementation

decodeArray(String value, int pgType, {String? connectionName}) {
  final len = value.length - 2;
  assert(value.codeUnitAt(0) == $lbrace && value.codeUnitAt(len + 1) == $rbrace,
      'Unsupported array (dimension prefix?): "$value".');
  if (len <= 0) return [];
  value = value.substring(1, len + 1);

  return _parseArray(value, len, pgType, connectionName);
    //[decodeValue] is identity for text types, jsonDecode for json
    //(a json null arrives quoted ("null") → decodes to null)
}