Oh, that's what it is. The override of the addition + operator by the concatenation operator || only happens if the right-hand side type is also a “concatenable” or NULL, not just the left side:
https://github.com/zzzeek/sqlalchemy/blob/rel_0_8_2/lib/sqlalchemy/types.py#L1017-L1023 and integer types are not marked as concatenable. Minimal test of this: from sqlalchemy.types import Text, Integer from sqlalchemy.sql import literal_column print literal_column("'foo'", type_=Text) + literal_column("'bar'", type_=Text) print literal_column("'foo'", type_=Text) + literal_column("3", type_=Integer) This prints: 'foo' || 'bar' 'foo' + 3 Not sure if it would be unambiguously correct to apply the concatenation override whenever the left side is a concatenable; seems superficially like it might be so, but there may well be cases where that's a problem. If so, this is probably not a bug. In any case, you can sidestep the whole issue of how + is interpreted, by being explicit about what you meant, using .concat(): print literal_column("'foo'", type_=Text).concat(literal_column("3", type_=Integer)) which prints what you wanted: 'foo' || 3 Gulli On Fri, Aug 30, 2013 at 3:34 PM, Florian Rüchel <florian.ruec...@gmail.com>wrote: > I recently had exactly the same problem on SQLAlchemy 0.8 where doing > something like "somestring" + Item.some_column would not result in a "||" > but in a "+" operator which sqlite could not handle. To note here in my > case: The "some_column" was the id, thus an integer. I'm not sure how > SQLAlchemy handles the operators exactly, but could this be a bug? Or is it > intended behaviour? > > > On Thursday, August 29, 2013 8:58:55 PM UTC+2, Gunnlaugur Briem wrote: > >> I would have expected the SQLite dialect to know how to compile concatto >> || if that's the operator. But failing that, something more explicit >> like this ought to do the trick: >> >> from sqlalchemy.sql import literal_column >> literal_column("'+ '").op('||')(seconds.c.n).op('**||')(literal_column("' >> seconds'")) >> >> Gulli >> >> >> >> On Thu, Aug 29, 2013 at 12:33 PM, Greg Yang <sorcer...@gmail.com> wrote: >> >>> I'm trying to get a series of datetimes using func.datetime. The format >>> of input is func.datetime(basetime, '+ NNN seconds'), which works nicely if >>> the shift applied is constant. However I need to add 10, 20, 30 seconds, >>> etc to this base time. So I want something like func.datetime(basetime, >>> concat('+', seconds.c.n, ' seconds')), but concat doesn't work for sqlite, >>> which concatenates using the '||' operator. Is there working method to >>> concat in sqlite? >>> >>> Failing that, is there another way to get at what I want with datetime >>> arithmetics? >>> >>> -- >>> 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 sqlalchemy+...@**googlegroups.com. >>> To post to this group, send email to sqlal...@googlegroups.com. >>> >>> Visit this group at >>> http://groups.google.com/**group/sqlalchemy<http://groups.google.com/group/sqlalchemy> >>> . >>> For more options, visit >>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>> . >>> >> >> -- > 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 sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/groups/opt_out. > -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.