Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update-SQL should allow for -NoPSTypeName #15

Open
bryanbcook opened this issue Mar 21, 2023 · 3 comments
Open

Update-SQL should allow for -NoPSTypeName #15

bryanbcook opened this issue Mar 21, 2023 · 3 comments

Comments

@bryanbcook
Copy link

Not sure exactly when it is occurring, but I'm using Update-SQL to write a PSCustomObject to a table and the pstypename column is being dynamically added to my table.

My code looks something like this:

$item = @{}
$item.First = "First"
$item.Last = "Last"

$data = [pscustomobject]$item

$sqlArgs = @{
   ConnectionString = $MyConnectionString
   TableName = "MyTable"
   RowKey = "Id"
}

$data | Update-Sql @sqlArgs

What I suspect is happening is that I have a database constraint, such as a non-null, which is rejecting the insert. The try-catch logic in Update-SQL appears to attempt to alter the table and then try again.

How can I prevent the pstypename from being added?

@StartAutomating StartAutomating changed the title pstypename column appears when I use Update-SQL Update-SQL should allow for -NoPSTypeName Mar 29, 2023
@StartAutomating
Copy link
Owner

@bryanbcook

Your timing is good, as Update-SQL is getting some updates.

Update-SQL and Select-SQL are designed to give you a PowerShell-friendly object, so the .PSTypeName behavior is "by design".

You can work around this design in a simple enough way as is:

Without -Force, Update-SQL will not change the table you're creating.

So if you don't want a PSTypeNames column, don't create one.

Alternatively, if you wanted to create the table and then drop the PSTypeName column, you could do that and then avoid -Force in the future.

Now since neither of these solutions is ideal, I've retitled the issue to something like what I feel the solution should be:

Adding a parameter to "opt-out" of creating the PSTypeName column.

Does this reply help you understand the issue?
Does this proposal sound like it will meet your needs?
Do you have a better parameter name in mind?

@bryanbcook
Copy link
Author

Without -Force, Update-SQL will not change the table you're creating.

I'm not using -Force and the column is being added.

@bryanbcook
Copy link
Author

I see there's some updates based on the commit. Are these changes ready for consumption or are they still work in progress?

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

No branches or pull requests

2 participants