Skip to content

Copy-DbaDbTableData - Name the Query requirement in the parameter guard message - #10678

Open
andreasjordan wants to merge 1 commit into
developmentfrom
fix-copy-tabledata-query-error-message
Open

Copy-DbaDbTableData - Name the Query requirement in the parameter guard message#10678
andreasjordan wants to merge 1 commit into
developmentfrom
fix-copy-tabledata-query-error-message

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Fixes #10676

Problem

Copy-DbaDbTableData -Query without -Table or -View answers with "You must pipe in a table or specify SqlInstance, Database and [View|Table]." - with -SqlInstance, -Database and -Query all supplied, that reads as if the wrong parameters were missing, on what is often the most expensive scenario to get an unclear error on (chunked transfers of large tables).

Why the requirement itself stays

The resolved SMO table or view is not just metadata garnish in -Query mode: it supplies the source connection context ($sqlObject.Parent), the structure AutoCreateTable scripts, the default -DestinationTable name, the clustered-index and primary-key lookups, and the source columns of the output object. Making -Table optional with -Query means rebuilding all of that from the query alone - a feature-level change with real design questions (what does AutoCreateTable script? what do the Source* output columns show?), not a bug fix. The help for -Query already documents the requirement ("Still requires specifying a Table or View parameter for metadata purposes").

What changed

The parameter guard now answers a -Query call with a message that names the actual gap:

When using Query, you still have to specify SqlInstance, Database and [View|Table]. The query determines the data that is copied, but the command needs the table or view as the source object for its metadata.

Everything else about the guard is unchanged, and calls without -Query keep the original message. Copy-DbaDbViewData exposes -Query too and splats into this function, so it gets the same message for free.

Tests

New regression test beside the existing -Query tests: calling with -Query and no -Table returns nothing and warns with the new message. Red on development (the generic message came back), green with the fix - through the testing-dbatools harness on both editions.

Thanks @JankeUwe for the report.

created by Claude and reviewed by Andreas Jordan

🤖 Generated with Claude Code

…rd message

With Query and no Table or View the guard answered with the generic message,
which reads as if SqlInstance or Database were missing. The requirement
itself stays: the resolved SMO object supplies the source connection
context, the structure AutoCreateTable scripts, the default destination
table name and the source columns of the output object, so removing it is a
feature change, not a bug fix. Copy-DbaDbViewData splats into this function
and gets the same message for free.

Fixes #10676

(do Copy-DbaDbTableData)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy-DbaDbTableData -Query still requires -Table, with an unhelpful error otherwise

1 participant