[Django] #29865: Add XOR for use in Q Queries

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #29865: Add XOR for use in Q Queries

Django
#29865: Add XOR for use in Q Queries
-------------------------------------+-------------------------------------
               Reporter:  spool      |          Owner:  nobody
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  2.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  xor
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 XOR seems to be available in [https://www.postgresql.org/docs/8.4/static
 /functions-math.html Postgresql], [https://dev.mysql.com/doc/refman/8.0/en
 /logical-operators.html MySQL], [https://docs.microsoft.com/en-us/sql/mdx
 /xor-mdx?view=sql-server-2017 SequelServer] and
 [https://docs.oracle.com/cd/E17952_01/mysql-5.1-en/logical-operators.html
 Oracle] but NOT [https://stackoverflow.com/questions/2294137/sqlite-
 exclusive-or-how-do-i-clear-a-flag sqlite]. Two stackoverflow questions
 cover this sort of thing: [https://stackoverflow.com/questions/50408142
 /django-models-xor-at-the-model-level] and
 [https://stackoverflow.com/questions/14711203/perform-a-logical-exclusive-
 or-on-a-django-q-object].

 I propose adding XOR to work with Q queries like the
 [https://stackoverflow.com/a/21220712/678486 answer]  to the second
 question above. This will be my first time making a major contribution so
 we'll see how this goes (apologies in advance if this is annoying!).

--
Ticket URL: <https://code.djangoproject.com/ticket/29865>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/048.9eda1ca96945ea4cf5f1f25983bed784%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29865: Add XOR for use in Q Queries

Django
#29865: Add XOR for use in Q Queries
-------------------------------------+-------------------------------------
     Reporter:  Griffith Rees        |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  xor                  |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * stage:  Unreviewed => Someday/Maybe


Comment:

 It's probably best to write to the DevelopersMailingList to see if there's
 consensus about this (although having a working patch may help evaluate
 the idea). I wonder if it's possible to emulate XOR on SQLite similar to
 what we do for some other database functions.

--
Ticket URL: <https://code.djangoproject.com/ticket/29865#comment:1>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.db5af5ab55076fd9fbf90390bd542373%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29865: Add XOR for use in Q Queries

Django
In reply to this post by Django
#29865: Add XOR for use in Q Queries
-------------------------------------+-------------------------------------
     Reporter:  Griffith Rees        |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  xor                  |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by felixxm):

 `XOR` is not officially supported on Oracle (see
 [https://docs.oracle.com/database/121/SQLRF/functions002.htm#SQLRF51178
 doc]) you pointed to the old MySQL documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/29865#comment:2>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.7edef6e4c2300865c15441a12465f4f0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29865: Add XOR for use in Q Queries

Django
In reply to this post by Django
#29865: Add XOR for use in Q Queries
-------------------------------------+-------------------------------------
     Reporter:  Griffith Rees        |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  xor                  |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * cc: felixxm (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29865#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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.d7f6b3eb1ee1b1d785678e6f44ca2806%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29865: Add XOR for use in Q Queries

Django
In reply to this post by Django
#29865: Add XOR for use in Q Queries
-------------------------------------+-------------------------------------
     Reporter:  Griffith Rees        |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  xor                  |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Marten Kenbeek):

 To be clear, you're talking about logical `XOR`, and not bitwise `XOR`?

 You linked to PostgreSQL's bitwise `XOR` operator, `#`. At the moment it
 does not have a logical `XOR` operator. The only
 [https://www.postgresql.org/docs/current/static/functions-logical.html
 logical operators] it supports are `AND`, `OR` and `NOT`.

--
Ticket URL: <https://code.djangoproject.com/ticket/29865#comment:4>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.c0ef5a44c60154f955ce8b00e1534061%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29865: Add XOR for use in Q Queries

Django
In reply to this post by Django
#29865: Add XOR for use in Q Queries
-------------------------------------+-------------------------------------
     Reporter:  Griffith Rees        |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  xor                  |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Nick Pope):

 Replying to [comment:4 Marten Kenbeek]:
 > To be clear, you're talking about logical `XOR`, and not bitwise `XOR`?

 As you've highlighted, this should be for logical `XOR` and not bitwise
 `XOR`. So this is only supported for MariaDB and MySQL which have `XOR`.

 This could be implemented by defining `Q.XOR` and `Q.__xor__()` and then
 propagating that around the place.
 It could be possible to support this for other backends by specifying
 `connection.features.supports_logical_xor = False` and then writing out
 the query differently.

 For `Q(a=1) ^ Q(b=2)`, the supporting backends would output `(a = 1 XOR a
 = 2)`, while the others could output `((a = 1 OR b = 2) AND NOT (a = 1 AND
 b = 2))`.

--
Ticket URL: <https://code.djangoproject.com/ticket/29865#comment:5>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.152d03c2a56a78ce53947dbb68fd56ca%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29865: Add XOR for use in Q Queries

Django
In reply to this post by Django
#29865: Add XOR for use in Q Queries
-------------------------------------+-------------------------------------
     Reporter:  Griffith Rees        |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  xor                  |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by jishansingh):

 XOR can be implemented by

 {{{
 def __xor__(self,other):
         return
 self.__or__(other).__and__(self.__invert__().__or__(other.__invert__()))
 }}}
 it works for sqlite (possibly for others)
 wouldn't it solves the problem

--
Ticket URL: <https://code.djangoproject.com/ticket/29865#comment:6>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.175327657d3947a03939ef4a15988c64%40djangoproject.com.