Skip to content

Feature Request: Handle DBNull as $null #9561

@replicaJunction

Description

@replicaJunction

Summary of the new feature/enhancement

As a scripter who has recently been working with databases quite a bit, it's become a headache to check constantly for [DBNull]::Value. It has a tendency to "leak" outside of my database code, and I need to start checking for DbNull values all over the rest of my code as well.

PowerShell already handles both $null and an empty string in the same manner. Can it also treat [DBNull]::Value as $null for purposes of conditionals?

Here is a contrived example of what I mean,

$myVar = $null
if (-not $myVar) {
  # This will run
  'MyVar is null'
}

$myVar = ''
if (-not $myVar) {
  # This will also run
  'MyVar is null'
}

$myVar = [DbNull]::Value
if (-not $myVar) {
  # This will not run
  'MyVar is null'
}

The last case is what I'd like to see changed - I'd like that to be handled in the same way as the first two cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions