#29291: Conditional expressions and ~Q queries
-------------------------------------+-------------------------------------
     Reporter:  Bo Marchman          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  2.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Bo Marchman):

 This is on Postgres 9.6.8.

 For `qs1`:
 {{{
 SELECT "test_app_application"."id",
        CASE
            WHEN NOT ("test_app_score"."reviewed" = TRUE
                      AND "test_app_score"."reviewed" IS NOT NULL) THEN
 TRUE
            ELSE FALSE
        END AS "needs_review"
 FROM "test_app_application"
 LEFT OUTER JOIN "test_app_score" ON ("test_app_application"."id" =
 "test_app_score"."application_id")
 WHERE CASE
           WHEN NOT ("test_app_score"."reviewed" = TRUE
                     AND "test_app_score"."reviewed" IS NOT NULL) THEN TRUE
           ELSE FALSE
       END = TRUE
 }}}

 And `qs2`:
 {{{
 SELECT "test_app_application"."id"
 FROM "test_app_application"
 WHERE NOT ("test_app_application"."id" IN
              (SELECT U1."application_id"
               FROM "test_app_score" U1
               WHERE U1."reviewed" = TRUE))
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29291#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.1d6d37466a4c6bdb9a576ed934668a46%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to