Skip to content

Regression: GetColumnSchema reports PostgreSQL array columns as System.Array instead of element[] (Npgsql 10.0.0 vs 9.0.4) #6399

@Gagarin23

Description

@Gagarin23

Summary

After upgrading Npgsql from 9.0.4 to 10.0.0, DbDataReader.GetColumnSchema()/GetColumnSchemaAsync() started reporting PostgreSQL array columns as untyped System.Array in DbColumn.DataType, whereas previously it was a strongly typed CLR array (e.g. System.Int32[]). This looks like a regression (or a breaking change) because the element type is known (int4[]) and Npgsql can map it.

Expected behavior

For a query returning int4[] (e.g. SELECT ARRAY[1,2,3]::int[]), schema[0].DataType should be typeof(int[]) (or at least preserve the element type information).

Actual behavior

  • Npgsql 9.0.4: schema[0].DataType == typeof(int[])
  • Npgsql 10.0.0: schema[0].DataType == typeof(Array)

Minimal repro

using Npgsql;

await using var connection = new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=postgres");
await using var command = connection.CreateCommand();
command.CommandText = "SELECT ARRAY[1,2,3]::int[]";
await connection.OpenAsync();
try
{
    await using var reader = await command.ExecuteReaderAsync();
    var schema = await reader.GetColumnSchemaAsync();
    Console.WriteLine("DbColumn.DataType: " + schema[0].DataType);
    Console.WriteLine("DbColumn.DataTypeName: " + schema[0].DataTypeName);
}
finally
{
    await connection.CloseAsync();
}

Environment

  • Npgsql: 9.0.4 ✅ / 10.0.0 ❌
  • PostgreSQL server version: 14
  • .NET: net10

Questions

Is this change intentional in 10.x (ADO.NET compliance / design decision), or should this be considered a regression?
If intentional: what is the recommended way to reliably get the element CLR type from schema for array columns (without parsing DataTypeName)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions