Skip to content

Import-DbaCsv: Add -NoColumnOptimize switch to skip post-import column shrinking #10194

@mbentham

Description

@mbentham

Summarize Functionality

When using Import-DbaCsv -AutoCreateTable to import multiple CSV files into the same table, the post-import column optimization (Optimize-ColumnSize) shrinks nvarchar(MAX) columns to fit the data from the first file. Subsequent imports then fail if later CSV files contain longer values in those columns.

A -NoColumnOptimize switch would skip the Optimize-ColumnSize step, leaving columns at nvarchar(MAX) so that all files can import successfully. This restores the old pre-optimization behavior on demand for multi-file import scenarios.

Is there a command that is similiar or close to what you are looking for?

Yes

Technical Details

The Optimize-ColumnSize function (in Import-DbaCsv.ps1) runs automatically after commit when $createdFatTable is true. The proposed change adds a [switch]$NoColumnOptimize parameter that, when set, suppresses the two Optimize-ColumnSize call sites (transaction and no-transaction paths around lines 1439 and 1452).

I'm planning to implement this and submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuretriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions