mikependon / RepoDB

A hybrid ORM library for .NET.
Apache License 2.0
1.68k stars 122 forks source link

Bug: PostgreSQL BinaryBulkMerge not working when table has name "schema.table" #1132

Open Mewriick opened 1 year ago

Mewriick commented 1 year ago

Hello,

I try to pefrom BulkMerge on PostgreSQL, but I receive error message.

SQL Error [3F000]: ERROR: schema "_RepoDb_BinaryBulkMerge_configuration" does not exist The problem is when RepoDb is try to create Temp table

   at Npgsql.Internal.NpgsqlConnector.<<ReadMessage>g__ReadMessageLong|226_0>d.MoveNext()
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Npgsql.NpgsqlDataReader.<NextResult>d__47.MoveNext()
   at Npgsql.NpgsqlDataReader.<NextResult>d__47.MoveNext()
   at Npgsql.NpgsqlCommand.<ExecuteReader>d__124.MoveNext()
   at Npgsql.NpgsqlCommand.<ExecuteReader>d__124.MoveNext()
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Npgsql.NpgsqlCommand.<ExecuteNonQuery>d__112.MoveNext()
   at RepoDb.DbConnectionExtension.<ExecuteNonQueryAsyncInternal>d__26.MoveNext()
   at RepoDb.NpgsqlConnectionExtension.<CreatePseudoTableAsync>d__86.MoveNext()
   at RepoDb.NpgsqlConnectionExtension.<PseudoBasedBinaryImportAsync>d__131.MoveNext()
   at RepoDb.NpgsqlConnectionExtension.<PseudoBasedBinaryImportAsync>d__131.MoveNext()
   at RepoDb.NpgsqlConnectionExtension.<BinaryBulkMergeBaseAsync>d__17`1.MoveNext()
   at RepoDb.NpgsqlConnectionExtension.<BinaryBulkMergeAsync>d__162`1.MoveNext()

Mapping

FluentMapper
    .Entity<Account>()
    .Table("configuration.account")
    .Primary(account => account.Id)
    .Identity(account => account.Id);

Used operation

var mergedRows = await connection.BinaryBulkMergeAsync(
  accounts,
  qualifiers: new List<Field> { new Field(nameof(Account.AccountNumber)) },
  mergeCommandType: RepoDb.Enumerations.PostgreSql.BulkImportMergeCommandType.OnConflictDoUpdate,
  //transaction: transaction,
  cancellationToken: cancellationToken);

Here is generated SQL for creating Temp table

SELECT "colums...." INTO TEMPORARY 
"_RepoDb_BinaryBulkMerge_configuration"."account" FROM "configuration"."account" WHERE (1 = 0);

I believe that the problem here is that there are quotes separated by comma. If I use this SQL everythink is working

SELECT "Id", "AccountNumber", "Status", "CgLevel", "Email", "Hwm"
INTO TEMPORARY "_RepoDb_BinaryBulkMerge_configuration.account" FROM "configuration"."account" WHERE (1 = 0);

Can you please help me, If I am doing something wrong with configuration?

Library Version:

Example: RepoDb v1.13.0 and RepoDb.PostgreSql.BulkOperation v1.13.0

mikependon commented 1 year ago

No, there is no problem from your side. It sounds to me that RepoDB SQL Builder has built an invalid SQL statement during data staging. We will look and fix this problem soon. Thanks for reporting this issue.

mikependon commented 1 year ago

@SergerGood - I have never validated your fix yet, I will keep this one open for now. But, I will do revisit ASAP and cover this in the next release.

jbrezina commented 10 months ago

Any updates on this please @mikependon?