@@ -445,6 +445,17 @@ void main() {
445445 );
446446 });
447447
448+ test ('an empty array decodes as a list of its element type, as a '
449+ 'non-empty one does' , () async {
450+ final row = (await conn.execute (
451+ "SELECT '{}'::text[], '{a}'::text[], '{}'::int4[], '{}'::bool[]" ,
452+ )).single;
453+ expect (row[0 ], isA <List <String >>());
454+ expect (row[1 ], isA <List <String >>());
455+ expect (row[2 ], isA <List <int >>());
456+ expect (row[3 ], isA <List <bool >>());
457+ });
458+
448459 test ('textArray' , () async {
449460 await expectReversible (
450461 '_text' ,
@@ -1292,6 +1303,26 @@ void main() {
12921303 expect (result, < int > []);
12931304 });
12941305
1306+ for (final (typeOid, elementOid, matcher) in [
1307+ (TypeOid .integerArray, TypeOid .integer, isA <List <int >>()),
1308+ (TypeOid .bigIntegerArray, TypeOid .bigInteger, isA <List <int >>()),
1309+ (TypeOid .textArray, TypeOid .text, isA <List <String >>()),
1310+ (TypeOid .varCharArray, TypeOid .varChar, isA <List <String >>()),
1311+ (TypeOid .booleanArray, TypeOid .boolean, isA <List <bool >>()),
1312+ (TypeOid .doubleArray, TypeOid .double , isA <List <double >>()),
1313+ (TypeOid .uuidArray, TypeOid .uuid, isA <List <String >>()),
1314+ ]) {
1315+ test ('An empty array (oid $typeOid ) keeps its element type, so a cast '
1316+ 'that holds for a non-empty one holds for it too' , () {
1317+ final context = CodecContext .withDefaults ();
1318+ // Postgres's wire format for an empty array: ndim=0, flags=0,
1319+ // elemtype, and no dimensions.
1320+ final bytes = concatInt32s ([0 , 0 , elementOid]);
1321+ final result = PostgresBinaryDecoder .convert (context, typeOid, bytes);
1322+ expect (result, matcher);
1323+ });
1324+ }
1325+
12951326 Uint8List int64Bytes (int value) =>
12961327 (ByteData (8 )..setInt64 (0 , value)).buffer.asUint8List ();
12971328 Uint8List int32Bytes (int value) =>
0 commit comments