Sitelet https://github.com/npgsql/npgsql/issues/6450
Skip to content

Return of the #4340. Error occured when writing to timestamptz from DateTime?[] #6450

Description

@Advitalitum

#4340

Reproduces if null in array goes before DateTime with Utc kind
Npgsql version: 10.0.1 (latest)

@NinoFloris FYI

public class UnitTest1
{
    [Fact]
    public void TestPostgresqlNullableArrayDateTimeParametersWithNullNotFirstInArrayWorksFine()
    {
        var connString = "Host=localhost;Username=postgres;Password=postgres;Database=testing";
        
        var connection = new NpgsqlConnection(connString);
        connection.Open();
        using var transaction = connection.BeginTransaction();

        var createTableCommand = connection.CreateCommand();
        createTableCommand.CommandText = "create table test (dt timestamp with time zone NULL);";
        createTableCommand.ExecuteNonQuery();
        
        var insertCommand = connection.CreateCommand();
        insertCommand.CommandText = "insert into test select * from unnest(@dt);";
        insertCommand.Parameters.AddWithValue("dt", new DateTime?[] {DateTime.UtcNow, DateTime.UtcNow, null});
        // This is fine, first we have DateTime.UtcNow, then null in array
        insertCommand.ExecuteNonQuery();

        transaction.Rollback();
    }
    
    [Fact]
    public void TestPostgresqlNullableArrayDateTimeParametersWithNullFirstInArrayIsBroken()
    {
        var connString = "Host=localhost;Username=postgres;Password=postgres;Database=testing";
        
        var connection = new NpgsqlConnection(connString);
        connection.Open();
        using var transaction = connection.BeginTransaction();

        var createTableCommand = connection.CreateCommand();
        createTableCommand.CommandText = "create table test (dt timestamp with time zone NULL);";
        createTableCommand.ExecuteNonQuery();
        
        var insertCommand = connection.CreateCommand();
        insertCommand.CommandText = "insert into test select * from unnest(@dt);";
        insertCommand.Parameters.AddWithValue("dt", new DateTime?[] {null, DateTime.UtcNow, DateTime.UtcNow});
        // This is broken (throws exception), first we have null, then, DateTime.UtcNow in array
        insertCommand.ExecuteNonQuery();

        transaction.Rollback();
    }
}

Activity

  1. changed the title [-]Return of the #4340[/-] [+]Return of the #4340. Error occured when writing to timestamptz from DateTime?[][/+] on Feb 17, 2026
  2. added a commit that references this issue on Feb 18, 2026
    221ae34
  3. NinoFloris commented on Feb 18, 2026

    @NinoFloris
    Member

    Thanks for the clear repro. I've created a fix and added a regression case.

  4. added a commit that references this issue on Feb 18, 2026
    f2d64c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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