Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #25912 --Added binary left/right shift operators to F expressions. #5815

Closed
wants to merge 2 commits into from

Conversation

anabelensc
Copy link
Contributor

@anabelensc anabelensc commented Dec 11, 2015

@timgraham timgraham changed the title Refs #25912 --Add binary left/right shift operators to F expressions Fixed #25912 --Added binary left/right shift operators to F expressions. Dec 11, 2015
@@ -345,6 +345,8 @@ Miscellaneous
* ``utils.version.get_version()`` returns :pep:`440` compliant release
candidate versions (e.g. '1.10rc1' instead of '1.10c1').

* The :class:`F expressions <django.db.models.F>` supported bitwise shift operators by ``>>`` and ``<<``.These operators are now available using ``.bitleftshift()`` and ``.bitrightshift()``.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to keep docs line length below 80 characters.

@adamchainz
Copy link
Sponsor Member

adamchainz commented Nov 5, 2016

I think adding this would be good to add for completion. I'd say it's slightly less surprising to implement the bit shifting with maths on Oracle rather than raising NotImplementedError, given that for other database functions such work arounds tend to get used.

@timgraham
Copy link
Member

All right, absent other feedback, I guess we'll proceed with this. Patch needs to be targeted at Django 1.11 and updated per Adam's comments.

@atombrella
Copy link
Contributor

@timgraham
Copy link
Member

timgraham commented Dec 30, 2016

I copied Oracle's implementation from BITAND but get ORA-00904: "BITSHIFT": invalid identifier. Not sure what could be wrong. \cc @felixxm

queries:
works:

UPDATE "EXPRESSIONS_NUMBER" SET "THE_INTEGER" =
 (BITAND("EXPRESSIONS_NUMBER"."THE_INTEGER",:arg0))
WHERE "EXPRESSIONS_NUMBER"."ID" = :arg

fails:

UPDATE "EXPRESSIONS_NUMBER" SET "THE_INTEGER" =
(BITSHIFT("EXPRESSIONS_NUMBER"."THE_INTEGER",:arg0))
WHERE "EXPRESSIONS_NUMBER"."ID" = :arg1

@timgraham
Copy link
Member

timgraham commented Dec 30, 2016

The linked documentation seems to be for something called "Document Automation Language (DAL)". I guess this is different than what the Oracle database supports.

[From stackoverflow] (http://stackoverflow.com/questions/20085462/bit-shifting-with-and-operation-in-sql-select):

Oracle's PL/SQL has a BITAND() function. Shift-right is the same as integer division by a power of 2. Assuming X is an integer, X >> 27 is the same as X / 134217728.

I'll try this approach.

@timgraham
Copy link
Member

Updated in #7770.

@timgraham timgraham closed this Dec 30, 2016
@felixxm
Copy link
Member

felixxm commented Dec 30, 2016

To be honest I have never heard about DAL, but I think that we can not use it in SQL or PL/SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants