Skip to content

Copy-DbaDbTableData -Query silently miscounts computed columns without -ForceExplicitMapping, corrupting data #10661

Description

@JankeUwe

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions