I ran in to a similar problem and was able to do something like this: DBSession.execute("set @temp=0;") DBSession.execute("Select @temp, ....;")
I tried using the "raw_connection" but that ended up not working due to different transactions. Above approach is working for now. On Wednesday, December 10, 2014 8:40:18 AM UTC-8, Michael Bayer wrote: > > this has to do with the DBAPI allowing it. It’s often possible but you > need to do it in such a way that the DBAPI lets it pass through. > > I’d start by experimenting with a DBAPI cursor, suppose this is pyodbc > (I’m not sure that this is, but this seems like SQL server) > > import pyodbc > > conn = pyodbc.connect(user=‘u’, password=’t’, dsn=‘mydsn’) > cursor = conn.cursor() > cursor.execute("set @temp=0;select (@temp:= @temp + 1) as ranking, userid > from mytable;”) > print cursor.fetchall() > > Alternatively, you can get at a cursor from SQLAlchemy using the > instructions at > http://docs.sqlalchemy.org/en/rel_0_9/core/connections.html#working-with-raw-dbapi-connections > . > > if you can get a DBAPI cursor working, then that’s what you’d do with > SQLAlchemy execute() also. if that doesn’t work, then you can post here > what the cursor can do that SQLAlchemy can’t. > > > > > > > On Dec 10, 2014, at 10:04 AM, shusheng liu <shushe...@gmail.com > <javascript:>> wrote: > > Hello, all. I want to execute an sql with temp variables in sqlalchemy > just like in mysql. > Here is my sql clause: > set @temp=0;select (@temp:= @temp + 1) as ranking, userid from mytable; > But sqlalchemy tells "This result object does not return rows. " > Who can tell me if I made some mistakes, or this is not supported by > sqlalchemy yet? > Thank you. > > -- > 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 <javascript:>. > To post to this group, send email to sqlal...@googlegroups.com > <javascript:>. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > > > -- 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/d/optout.