I've looked around both in the current DB layer and in
Queryset-refactor, but it's possible I've missed something. If this
already exists, then give me the shaming I deserve. Otherwise...
Would anyone object to it being just another __ operation? For
instance, Poll.objects.filter(column__bitand=4). Is there a preference
whether this should be __and or __bitand?
I don't know if this makes sense for | (bitwise-OR), since you would
need to be able to specify something more like this:
"SELECT * FROM table WHERE column | 4 > 12;".
"SELECT * FROM table WHERE column | 4 = 12;".
Which may not be appropriate for a simple queryset operator in Django.
However, it would be cool if there was some way to support that with a
more complicated Q() or the like, but I could see it being out of scope
of Django, so ignore this part if so.
Bitwise-XOR, I don't know, some specific usages maybe.
I've already verified that all the DBs Django supports have some
mechanism for doing the basic bitwise operations.[1][2][3][4][5]
I don't mind doing this only against the qs-rf branch, and I can build
the tests and patch, but wanted to get the community opinion first. I'm
+1 on & (bitwise-AND), -0 on | (bitwise-OR, pending someone giving a
neat example), and +0 on bitwise-XOR/the rest, but would like to find
some way to be +1 on all of them.
Thoughts?
Thanks,
George
[1] SQLite: http://www.sqlite.org/changes.html
[2] MySQL: http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html
[3] MSSQL: http://www.functionx.com/sqlserver/Lesson03.htm
[4] PostgreSQL:
http://www.postgresql.org/docs/8.1/interactive/functions-math.html
[5] Oracle: http://www.jlcomp.demon.co.uk/faq/bitwise.html
Yeah, I'd object. I don't see it as common enough to warrant inclusion.
You can achieve the same functionality either with extra(where=...) or a
custom Q-like object, so I'm inclined to leave it out of core.
By the way, in the queryset-refactor Q-like objects will have access to
the full query class, which includes the model, so you'll be able to
write something like Bit(foo__and=4) and when it comes time to produce
the SQL, your Bit class will be able to work out the right column name
for model field "foo".
Regards,
Malcolm
--
Quantum mechanics: the dreams stuff is made of.
http://www.pointy-stick.com/blog/