Fix PostgreSQL bulk copy identity column handling

- Modified FastestProvider to handle identity columns differently for PostgreSQL/Vastbase
- Added logic to exclude identity columns from bulk copy operations for PostgreSQL
- Commented out identity column restriction in PostgreSQLFastBuilder
- PostgreSQL bulk copy now supports tables with identity columns by excluding them

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yayaxxww
2025-10-24 20:28:21 +08:00
parent 769836c5e8
commit 17cb502564
2 changed files with 26 additions and 7 deletions

View File

@@ -86,7 +86,7 @@ namespace SqlSugar
List<string> uInt64TypeName = new List<string>();
foreach (DataColumn item in tempDataTable.Columns)
{
if (item.DataType == typeof(UInt64))
if (item.DataType == typeof(UInt64))
{
uInt64TypeName.Add(item.ColumnName);
}
@@ -99,8 +99,27 @@ namespace SqlSugar
dt.Columns.Add(item.ColumnName, item.DataType);
}
}
bool supportIdentity = true;
if (this.context.CurrentConnectionConfig.DbType == DbType.PostgreSQL || this.context.CurrentConnectionConfig.DbType == DbType.Vastbase)
{
supportIdentity = false;
}
if (!supportIdentity)
{
// PostgreSQL/Vastbase不支持自增主键导入
foreach (var identityColumnInfo in this.entityInfo.Columns.Where(it => it.IsIdentity))
{
if (dt.Columns.Contains(identityColumnInfo.DbColumnName))
{
dt.Columns.Remove(identityColumnInfo.DbColumnName);
}
}
}
dt.TableName = GetTableName();
var columns = entityInfo.Columns;
var columns = supportIdentity ? entityInfo.Columns : entityInfo.Columns.Where(it => !it.IsIdentity).ToList();
if (columns.Where(it=>!it.IsIgnore).Count() > tempDataTable.Columns.Count)
{
var tempColumns = tempDataTable.Columns.Cast<DataColumn>().Select(it=>it.ColumnName);

View File

@@ -47,11 +47,11 @@ namespace SqlSugar
var columns = this.Context.DbMaintenance.GetColumnInfosByTableName(this.entityInfo.DbTableName);
try
{
var identityColumnInfo = this.entityInfo.Columns.FirstOrDefault(it => it.IsIdentity);
if (identityColumnInfo != null)
{
throw new Exception("PgSql bulkcopy no support identity");
}
//var identityColumnInfo = this.entityInfo.Columns.FirstOrDefault(it => it.IsIdentity);
//if (identityColumnInfo != null)
//{
// throw new Exception("PgSql bulkcopy no support identity");
//}
BulkCopy(dt, copyString, conn, columns);
}
catch (Exception ex)