EFCore.BulkExtensions icon indicating copy to clipboard operation
EFCore.BulkExtensions copied to clipboard

BulkInsert() with Posgresql "timestamp(2)" type causes error 'A PostgreSQL type with the name timestamp(2) with time zone was not found in the database'

Open philipag opened this issue 3 years ago • 3 comments

If I use "timestamp" without precision then it works. The db is created using code first EF Core and I can see the correct precision in pgAdmin. It seems that BulkExtension is not handling precision properly with some types? Restarting the app or specifying LoadTableComposites=true or connection.ReloadTypes() make no difference.

This is using .Net 7 preview 1 with the latest BulkExtensions nuget. I have no prior experience with this package but having a quick look at the sources it seems that perhaps the problem is that some precision cases are not handled in PostgreSqlAdapter.cs?

if (columnType.StartsWith("character")) // when MaxLength is defined: 'character(1)' or 'character varying' columnType = "character"; // 'character' is like 'string' else if (columnType.StartsWith("varchar")) columnType = "varchar"; else if (columnType.StartsWith("numeric")) columnType = "numeric";

philipag avatar Feb 25 '22 20:02 philipag

Net 7 is not yet supported. Can you confirm the issue also exist with .Net 6. If it does write an example/test to reproduce the issue.

borisdj avatar Feb 26 '22 14:02 borisdj

If memory serves me I am pretty sure this issue existed in 6 as well.

philipag avatar Feb 26 '22 15:02 philipag

debugging this a bit shows that the problem could lie with Npgsql. It seems that it is not loading timestamp(n) types from the db which is by EFCore.BulkExtensions does not see them. Not sure why this is not a problem with normal context inserts.

However adding the type manually does not work because it seems EFCore.BulkExtensions does not use the user types (although it should):

NpgsqlConnection.GlobalTypeMapper.MapComposite<DateTime>("timestamp(3) with time zone");

philipag avatar Mar 08 '22 10:03 philipag

Fixed, new nugget will be published in a few days.

borisdj avatar May 10 '23 20:05 borisdj