[sqlalchemy] Re: Using .label() on boolean expressions

2007-01-19 Thread Michael Bayer



On Jan 19, 2007, at 11:49 AM, King Simon-NFHD78 wrote:


because that would be a function rather than a boolean expression, and
functions can be labelled. I knew I couldn't call 'sa.func.if', but I
thought it would be nice if you could use sa.func.if_  - the
_FunctionGateway object could strip the trailing underscore from the
name.


good idea, i put that in r2218.





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Using .label() on boolean expressions

2007-01-19 Thread Michael Bayer


I just changed the inheritance of BooleanExpression to be from  
BinaryExpression so it retains all the semantics of a  
BinaryExpression, rev 2217.  this required a slight tweak in the  
orm's Query.select() method to properly detect a "where" criterion  
but was otherwise not a big deal.


On Jan 19, 2007, at 10:11 AM, King Simon-NFHD78 wrote:



Hi,

I don't know if this is valid SQL, but MySQL seems to accept it... I'd
like to write a query that looks like:

 SELECT s.result LIKE 'Pass%' AS pass
 ...

Which would return 1 or 0 for each row depending on whether the result
column begins with Pass. In SQLAlchemy this would become:

 sa.select([s.c.result.startswith('Pass').label('pass')] ...)

Without the .label(), this works, but I can't label it because
BooleanExpressions don't have a label method.

Is there another way to do this?

Thanks,

Simon

>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Using .label() on boolean expressions

2007-01-19 Thread King Simon-NFHD78


Simon King wrote:


I don't know if this is valid SQL, but MySQL seems to accept 
it... I'd like to write a query that looks like:


  SELECT s.result LIKE 'Pass%' AS pass
  ...

Which would return 1 or 0 for each row depending on whether 
the result column begins with Pass.




Another way I tried to do this was to use the SQL:

SELECT IF(s.result LIKE 'Pass%', 'Pass', 'Fail') AS pass
...

because that would be a function rather than a boolean expression, and
functions can be labelled. I knew I couldn't call 'sa.func.if', but I
thought it would be nice if you could use sa.func.if_  - the
_FunctionGateway object could strip the trailing underscore from the
name. It took me a while to realise I could use sa.func.IF, but the
capital letters look ugly :-). Alternatively, _FunctionGateway could be
given a __call__ method which would take the name as a parameter, so you
could use 'sa.func("if")'.

Just an idea.

Simon

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---