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

Open
opened 2026-01-22 15:15:55 +01:00 by admin · 0 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:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5734