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'
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";
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.
If memory serves me I am pretty sure this issue existed in 6 as well.
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");
Fixed, new nugget will be published in a few days.