Re: [sqlalchemy] creating a cte from a string and some params

2013-11-29 Thread Chris Withers
On 29/11/2013 05:09, Michael Bayer wrote: On Nov 28, 2013, at 7:54 PM, Chris Withers ch...@simplistix.co.uk wrote: So far, I got: inst = aliased(Part) unit = aliased(Part) query = session.query( inst.idea_id, inst.instrument_id, func.sum(inst.quantity),

[sqlalchemy] Struggling with a join

2013-11-29 Thread Glenn Wilkinson
Hi all, I'm struggling to get a join to work, as below: [...] #Table definitions table = Table('vends', MetaData(), Column('mac', String(64), primary_key=True), Column('vendor', String(20) ), Column('vendorLong',

Re: [sqlalchemy] Struggling with a join

2013-11-29 Thread Simon King
On Fri, Nov 29, 2013 at 1:55 PM, Glenn Wilkinson glenn.wilkin...@gmail.com wrote: Hi all, I'm struggling to get a join to work, as below: [...] #Table definitions table = Table('vends', MetaData(), Column('mac', String(64), primary_key=True),

Re: [sqlalchemy] Re: Struggling with a join

2013-11-29 Thread Simon King
Ah, OK, I see what you mean. The way that you are producing the JOIN, although it works, is probably not exactly what you wanted. With this: s=select([proxs.c.mac]).outerjoin(vends, proxs.c.mac == vends.c.mac) ...you are first creating a query that selects from the proxs table, then treating

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-29 Thread Michael Bayer
Sure i don't mind an enhancement to text(), a method like as_subquery(c1, c2 ...) that turns it into a FromClause On Nov 29, 2013, at 4:20 AM, Chris Withers ch...@simplistix.co.uk wrote: On 29/11/2013 05:09, Michael Bayer wrote: On Nov 28, 2013, at 7:54 PM, Chris Withers

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-29 Thread Michael Bayer
here’s a patch: http://www.sqlalchemy.org/trac/ticket/2877 it’s quite short. I just don’t like the current contract of SelectBase, which has many methods that don’t apply here, so might want to rework the base classes. On Nov 22, 2013, at 5:06 AM, Chris Withers ch...@simplistix.co.uk

Re: [sqlalchemy] Running an externally supplied SQL statement with special characters

2013-11-29 Thread Ivan Kalinin
Actually, using the session.connection().execute did help! Also, I think there is an option of creating a TextClause subclass with a different search regex that, for example, matches nothing. But it's a bit of an overkill, IMO. On Fri, Nov 29, 2013 at 10:41 PM, Michael Bayer

Re: [sqlalchemy] Running an externally supplied SQL statement with special characters

2013-11-29 Thread Michael Bayer
yes, that workaround works, but much more simply, using a backslash in text() should work as well On Nov 29, 2013, at 2:01 PM, Ivan Kalinin pupss...@gmail.com wrote: Actually, using the session.connection().execute did help! Also, I think there is an option of creating a TextClause

Re: [sqlalchemy] Running an externally supplied SQL statement with special characters

2013-11-29 Thread Ivan Kalinin
The point is we get those SQL statements from an external source and we'd prefer not to modify them. I do understand its a rare use-case of SA, but having a DumbTextClause or an option regex parameter in TextClause constructor could help. On Fri, Nov 29, 2013 at 11:06 PM, Michael Bayer

Re: [sqlalchemy] Running an externally supplied SQL statement with special characters

2013-11-29 Thread Michael Bayer
if you’re using the text() constructor directly anyway, you can just define a helper like this: def unescaped_text(sql): return text(sql.sub(‘:’, ‘\\:’)) On Nov 29, 2013, at 2:15 PM, Ivan Kalinin pupss...@gmail.com wrote: The point is we get those SQL statements from an external source

Re: [sqlalchemy] creating a cte from a string and some params

2013-11-29 Thread Michael Bayer
here you go, give it a spin: http://docs.sqlalchemy.org/en/rel_0_9/changelog/migration_09.html#new-text-capabilities On Nov 29, 2013, at 12:13 PM, Michael Bayer mike...@zzzcomputing.com wrote: here’s a patch: http://www.sqlalchemy.org/trac/ticket/2877 it’s quite short. I just don’t