Environment: dbatools 2.7.1 and 2.8.2 (reproduced on both), SQL Server
Description:
When the destination table has a computed column (e.g. at ordinal position 3) and Copy-DbaDbTableData is used in -Query mode without -ForceExplicitMapping, the cmdlet falls back to implicit ordinal column mapping that appears to count the computed column as a real target slot. Every column after it silently shifts by one position. No error or warning is produced - values land in the wrong columns.
Repro:
- Destination table with 108 columns, one computed column at ordinal position 3.
- Source query returns matching non-computed columns in order.
- Run
Copy-DbaDbTableData -SqlInstance <src> -Database <db> -Query "SELECT ..." -DestinationSqlInstance <dst> -DestinationDatabase <db> -DestinationTable <table> without -ForceExplicitMapping.
- After copy, two locale-ID columns (
GV_Source_ID/GV_Produkt in our schema) land swapped/wrong (0 vs 1033) - confirmed by direct row inspection, not a formatting artifact.
Expected:
Either exclude computed columns from ordinal counting by default, or clearly document that -ForceExplicitMapping is required whenever the destination has any computed column - ideally with a loud warning when it's omitted and a computed column is detected on the target.
Workaround used:
Built a custom SqlBulkCopy wrapper with explicit name-based ColumnMappings, bypassing -Query mode's implicit mapping entirely.
Environment: dbatools 2.7.1 and 2.8.2 (reproduced on both), SQL Server
Description:
When the destination table has a computed column (e.g. at ordinal position 3) and
Copy-DbaDbTableDatais used in-Querymode without-ForceExplicitMapping, the cmdlet falls back to implicit ordinal column mapping that appears to count the computed column as a real target slot. Every column after it silently shifts by one position. No error or warning is produced - values land in the wrong columns.Repro:
Copy-DbaDbTableData -SqlInstance <src> -Database <db> -Query "SELECT ..." -DestinationSqlInstance <dst> -DestinationDatabase <db> -DestinationTable <table>without-ForceExplicitMapping.GV_Source_ID/GV_Produktin our schema) land swapped/wrong (0 vs 1033) - confirmed by direct row inspection, not a formatting artifact.Expected:
Either exclude computed columns from ordinal counting by default, or clearly document that
-ForceExplicitMappingis required whenever the destination has any computed column - ideally with a loud warning when it's omitted and a computed column is detected on the target.Workaround used:
Built a custom
SqlBulkCopywrapper with explicit name-basedColumnMappings, bypassing-Querymode's implicit mapping entirely.