Small documentation suggestion

Issue #1354 resolved
Former user created an issue

I was having problems getting a bitwise And working until I found the helpful post quoted below. I think the problem is that there is no reference to the word "bitwise" in the documentation so users' searches for this information are hard. I'd suggest adding to the existing documentation at

http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/schema.html#sqlalchemy.schema.Column.op

some text such as:

"This function can also be used to make bitwise operators explicit. For example

somecolumn.op('&')(0xff)

is a bitwise AND of the value in somecolumn."

~Matt mdoar@pobox.com

The original post:

Subject: sqlalchemy Re: Bitwise operations in SQLAlchemy Actions... From: Christoph Zwerschke (ci...@online.de) Date: Aug 11, 2008 10:43:16 am List: com.googlegroups.sqlalchemy

Michael Bayer schrieb:

while it might be nice to somehow support usage of &, | and ^ directly for this (although their usage for regular AND and OR is pretty entrenched at this point), you can achieve bitwise operations using the generic "op()" operator, as in x.op('&')(y), etc.

but I would favor the addition of bitwise_and(), bitwise_or(), and bitwise_xor() as core expression language additions.

I'd prefer SA expressions to conform with the Python and SQL expressions as far as possible. These kind of exceptions make using it cumbersome.

But of course I also understand that the regular AND (OR, NOT) is much for frequent, and using the and_ (or_, not_) function is much less readable, so abusing & (|, ~) for this purposes makes sense, too. Plus I just noticed it's already documented. So I trust your insight to make the right choice. If things are well documented, one can live with a few hitches. In this case, the workaround for the real bitwise operations should be mentioned in the sql expression language tutorial.

-- Christoph

Comments (3)

  1. Log in to comment