Michael Bayer schrieb:
>
> On Sep 8, 2008, at 3:27 PM, Diez B. Roggisch wrote:
>
>> But it fails with
>>
>> raise exc.DBAPIError.instance(statement, parameters, e,
>> connection_invalidated=is_disconnect)
>> OperationalError: (OperationalError) unrecognized token: ":" ...
>
> text() treats :name as a bind parameter, so you'd have to escape the
> ":" using a backslash "\:\:float". you might have a cleaner
> expression if you use a string just for the column expression itself
> (also the bind param escaping wouldn't occur):
>
> select
> ([literal_column
> ("count(*)::float")]).where(questions.c.id==at.c.question_id)
This does fail with the same error - the :: isn't properly recognized. I
tried to escape as you said:
select([literal_column(r"count(*)\:\:float")],
and_(at.c.question_id == qt.c.id)).as_scalar()
but this is the result:
count(*)\\:\\:float
OperationalError: (OperationalError) unrecognized token: "\".
>
>> Additonally, I'd of course prefer to formulate the subqueries using SA
>> as well - but that fails as I can't divide selects.
>
> a select marked as "as_scalar()" should be usable in a division
> equation:
>
> >>> from sqlalchemy import *
> >>> s = select([1]).as_scalar()
> >>> s2 = select([2]).as_scalar()
> >>> print s / s2
> (SELECT 1) / (SELECT 2)
> >>>
That works, great! One question: How can I influence the column-name
generated for the scalar expressions? I want to use them in the
order_by-clause.
Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---