RepoDB icon indicating copy to clipboard operation
RepoDB copied to clipboard

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

Open Mewriick opened this issue 2 years ago • 3 comments

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

Mewriick avatar Feb 10 '23 13:02 Mewriick

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 avatar Feb 11 '23 18:02 mikependon

@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.

mikependon avatar Mar 16 '23 20:03 mikependon

Any updates on this please @mikependon?

jbrezina avatar Aug 29 '23 12:08 jbrezina