-
Notifications
You must be signed in to change notification settings - Fork 876
Open
Description
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();
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels