NEQ does not work on Postgres with bool field. #5735

Closed
opened 2026-01-22 15:15:57 +01:00 by admin · 5 comments
Owner

Originally created by @dekey on GitHub (Oct 9, 2017).

Originally assigned to: @lcobucci on GitHub.

Hi. I have a table contact with bool field on Postgres 9.6

CREATE TABLE contact
(
    id bigserial,
    name character varying(255),
    email character varying(255),
    unsubscribed boolean,
    CONSTRAINT contact_pkey PRIMARY KEY (id)
);

When I try to create query builder for this table with condition not equal to true

return $em->createQueryBuilder()
    ->select('p.id');
    ->from(Contact::class, 'c')
    ->andWhere(
        $qb->expr()->neq(
            'c.unsubscribed',
            $qb->expr()->literal(true)
        )
    );

Got next SQL:
SELECT i0_.id AS id_0 FROM contact i0_ WHERE i0_.unsubscribed <> true;

The main problem that condition <> does not work with boolean field. Instead of <> on Postgres is using condition IS NOT TRUE.

I know that I could use native query, but in some cases I can`t use it. I would like to know your comments about.
Thank you in advance.

Originally created by @dekey on GitHub (Oct 9, 2017). Originally assigned to: @lcobucci on GitHub. Hi. I have a table contact with bool field on `Postgres` 9.6 ``` CREATE TABLE contact ( id bigserial, name character varying(255), email character varying(255), unsubscribed boolean, CONSTRAINT contact_pkey PRIMARY KEY (id) ); ``` When I try to create query builder for this table with condition `not equal` to true ``` return $em->createQueryBuilder() ->select('p.id'); ->from(Contact::class, 'c') ->andWhere( $qb->expr()->neq( 'c.unsubscribed', $qb->expr()->literal(true) ) ); ``` Got next SQL: `SELECT i0_.id AS id_0 FROM contact i0_ WHERE i0_.unsubscribed <> true;` The main problem that condition `<>` does not work with boolean field. Instead of `<>` on Postgres is using condition `IS NOT TRUE`. I know that I could use native query, but in some cases I can`t use it. I would like to know your comments about. Thank you in advance.
admin added the BugInvalidMissing Tests labels 2026-01-22 15:15:57 +01:00
admin closed this issue 2026-01-22 15:15:58 +01:00
Author
Owner

@lcobucci commented on GitHub (Oct 9, 2017):

@dekey it sounds like a bug, could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing (also to ensure it works on different platforms).

You can find examples on 388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket

@lcobucci commented on GitHub (Oct 9, 2017): @dekey it sounds like a bug, could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing (also to ensure it works on different platforms). You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@dekey commented on GitHub (Oct 16, 2017):

Hi @lcobucci. Have added test
https://github.com/doctrine/doctrine2/pull/6775

@dekey commented on GitHub (Oct 16, 2017): Hi @lcobucci. Have added test https://github.com/doctrine/doctrine2/pull/6775
Author
Owner

@lcobucci commented on GitHub (Oct 16, 2017):

@dekey awesome, thanks!

I'll take a look on it ASAP =)

@lcobucci commented on GitHub (Oct 16, 2017): @dekey awesome, thanks! I'll take a look on it ASAP =)
Author
Owner

@mateuszsip commented on GitHub (Oct 22, 2017):

Hi guys,
I took a look at code to think how it could be handled, but I don't see any existing implementation handling query differences like this one.
Did I miss something?

Should Doctrine\DBAL\Query\Expression\ExpressionBuilder get a platform-specific override support using injected Connection? What about filed type? Issue is boolean specific.
Is it worth potential complexity gain?

Would love to help, but don't know internals enough.

@mateuszsip commented on GitHub (Oct 22, 2017): Hi guys, I took a look at code to think how it could be handled, but I don't see any existing implementation handling query differences like this one. Did I miss something? Should `Doctrine\DBAL\Query\Expression\ExpressionBuilder` get a platform-specific override support using injected `Connection`? What about filed type? Issue is boolean specific. Is it worth potential complexity gain? Would love to help, but don't know internals enough.
Author
Owner

@lcobucci commented on GitHub (Nov 26, 2017):

As explained on #6775 this is a DBAL issue and so I'll be closing this ticket as invalid. We should move the test and find a fix for it on https://github.com/doctrine/dbal instead.

@lcobucci commented on GitHub (Nov 26, 2017): As explained on #6775 this is a DBAL issue and so I'll be closing this ticket as `invalid`. We should move the test and find a fix for it on https://github.com/doctrine/dbal instead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5735