On Aug 30, 2013, at 6:32 PM, Florian Rüchel <[email protected]> wrote:
> Okay so basically what you are saying is that this is intended behaviour?
> I've been trying to dig through the source for quite some time now but
> finding the point where it is decided is harder than I thought. Could you
> explain why String + Int gives the operator "add" and not "concat_op"?
because concatenable says this:
def _adapt_expression(self, op, other_comparator):
if op is operators.add and isinstance(other_comparator,
(Concatenable.Comparator, NullType.Comparator)):
return operators.concat_op, self.expr.type
else:
return op, self.expr.type
that is, the other side has to be concatenable also, or nulltype.
if on 0.8 at least you can always use the concat() operator directly:
from sqlalchemy.sql import table, column, operators
from sqlalchemy import Integer, String
print column('x', String) + column('y', Integer)
print operators.concat_op(column('x', String), column('y', Integer))
print column('x', String).concat(column('y', Integer))
http://docs.sqlalchemy.org/en/rel_0_8/core/metadata.html?highlight=concat#sqlalchemy.schema.Column.concat
>
> On 31.08.2013 00:28, Michael Bayer wrote:
>> (note: please keep answering the emails! this is great, I just happen to
>> have a little bit of net access here..)
>>
>> here's how you can turn any expression into any other type for Python-side
>> operator or data coercion purposes (that is, like a CAST but doesn't render
>> CAST on the database):
>>
>> from sqlalchemy import type_coerce
>>
>> type_coerce(any_expression, String) + type_coerce(any_other_expression,
>> String)
>>
>> you'll get <any expression> || <any other expression> no matter what the two
>> sides are.
>>
>> (if you don't, then *that's* the bug)
>>
>>
>> On Aug 30, 2013, at 1:34 PM, Jonathan Vanasco <[email protected]> wrote:
>>
>>> This might be a bug then.
>>>
>>> String || Integer ; Integer || String
>>> - PostgreSQL and sqlite both allow for a sting & integer to be concat
>>> together into a string. Order does not matter.
>>>
>>> Integer || Integer
>>> - PostgreSQL will error if 2 ints are concat together.
>>> - sqlite seems to cast both into a string, and returns a string ( i.e.
>>> "Select 1 || 2" == "12" == str(12) )
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "sqlalchemy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/sqlalchemy.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
signature.asc
Description: Message signed with OpenPGP using GPGMail
