Skip to content

Cannot set NULL to a nullable boolean column in PostgreSQL #7022

@ribeiropaulor

Description

@ribeiropaulor

Bug Report

Q A
Version 3.10.x

Summary

PostgreSQL allows 3 values in a boolean column: TRUE, FALSE and NULL.

I cannot set NULL to a nullable boolean column using PostgreSQL.

Current behavior

Instead of passing NULL to PostgreSQL, it forwards as FALSE.

Expected behavior

I should pass as NULL, so, when I fetch the row, I get NULL as result.

How to reproduce

The functional test Doctrine\DBAL\Tests\Functional\BooleanBindingTest could be modified to test the insertion of NULL values. Then it would certainly fail. The following excerpt of Doctrine\DBAL\Driver\PgSQL\Statement is responsible for mishandling NULL values. It does not care about NULL values as it chooses between TRUE or FALSE to forward the value.

    /** {@inheritDoc} */
    public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
    {
        if (! isset($this->parameterMap[$param])) {
            throw UnknownParameter::new((string) $param);
        }

        if ($type === ParameterType::BOOLEAN) {
            $this->parameters[$this->parameterMap[$param]]     = (bool) $value === false ? 'f' : 't';
            $this->parameterTypes[$this->parameterMap[$param]] = ParameterType::STRING;
        } else {
            $this->parameters[$this->parameterMap[$param]]     = $value;
            $this->parameterTypes[$this->parameterMap[$param]] = $type;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions