[sqlalchemy] Re: Best practice for binding the engine

2014-03-12 Thread Bao Niu
Ok, let me try rephrasing my question. Is binding an engine/connection simultaneously to a Session and a Table considered bad practice? I've looked up the documentation but not sufficiently confident about this. There seems no definite/official answer to this. Could some experienced users help

Re: [sqlalchemy] Re: Best practice for binding the engine

2014-03-12 Thread Simon King
The order of resolution is described here: http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#sqlalchemy.orm.session.Session.get_bind Binds on the session take priority over binds on metadata (passing an engine to declarative_base binds the metadata for that base class). As far as best

Re: [sqlalchemy] Re: Best practice for binding the engine

2014-03-12 Thread Bao Niu
Yes it is clearly documented there, I need to refine my reading skills:) thxs Simon! Your explanation makes it much easier to understand for a newbie like me. On Mar 12, 2014 3:24 AM, Simon King si...@simonking.org.uk wrote: The order of resolution is described here:

[sqlalchemy] sql expression performance is bad ?

2014-03-12 Thread Ni Wesley
Hi guys, I hit a problem when using sqlalchemy operating mysql. First, let me clarify my code frames. I have a web service to receive http requests, then, it send task to a tcp server via zeromq pull/push mode, tcp server pull and do some push work to cell phone. I hit a problem that, tcp

Re: [sqlalchemy] sql expression performance is bad ?

2014-03-12 Thread Michael Bayer
On Mar 12, 2014, at 8:32 AM, Ni Wesley nisp...@gmail.com wrote: Hi guys, I hit a problem when using sqlalchemy operating mysql. First, let me clarify my code frames. I have a web service to receive http requests, then, it send task to a tcp server via zeromq pull/push mode, tcp

Re: [sqlalchemy] sql expression performance is bad ?

2014-03-12 Thread Ni Wesley
I am sorry... The reason why I close the session everytime is, from some googled docs, somebody say the engine pool is full because some sessions are not closed... I just realized that I can have a try directly use engine.execute, instead of session... I will look at the link you pasted later.

[sqlalchemy] How to set distinct query properly

2014-03-12 Thread pyArchInit ArcheoImagineers
Hi to all, I looked for around the web without success. I need to reproduce this kind of SQL distinct query: SELECT DISTINCT column1 from table where column3= 'Value' or two or more: SELECT DISTINCT column1,column2 from table where column3= 'Value' I tried something like this without success:

Re: [sqlalchemy] HSTORE intermittent bug

2014-03-12 Thread Ben Boule
Hi Michael, Is there any more information about this issue? I think I may be running into this problem, but I do not see any difference using the latest versions of SQLAlchemy (0.8.5 and 0.9.3), the workaround does not seem to help, and I can't find anything in the SQLAlchemy bitbucket bug

Re: [sqlalchemy] group max, outerjoin, and subquery

2014-03-12 Thread Michael Weylandt
Hi Mike, Thanks for the help. I'm not sure that's the right set of subqueries though; looking at the generated SQL, the result seems closer to: CREATE TABLE #B_temp AS (SELECT * FROM B WHERE id IN (SELECT max(number) mn FROM B GROUP BY A_id)) CREATE TABLE #C_temp AS (SELECT * FROM C WHERE

Re: [sqlalchemy] group max, outerjoin, and subquery

2014-03-12 Thread Michael Weylandt
Hi Mike, I've simplified the query I'm looking for into a one line: (not sure why I didn't think of HAVING earlier -- definitely making a mountain from molehills) SELECT A.*, B1.*, C1.* FROM A LEFT OUTER JOIN (SELECT * FROM B GROUP BY A_id HAVING number = max(number)) AS B1 ON A.id = B1.A_id

Re: [sqlalchemy] How to set distinct query properly

2014-03-12 Thread Michael Bayer
On Mar 12, 2014, at 10:36 AM, pyArchInit ArcheoImagineers pyarchi...@gmail.com wrote: Hi to all, I looked for around the web without success. I need to reproduce this kind of SQL distinct query: SELECT DISTINCT column1 from table where column3= 'Value' or two or more: SELECT DISTINCT

Re: [sqlalchemy] HSTORE intermittent bug

2014-03-12 Thread Michael Bayer
no, you'd need to produce a standalone, reproducing test case, thanks. On Mar 12, 2014, at 11:51 AM, Ben Boule b...@cloudlock.com wrote: Hi Michael, Is there any more information about this issue? I think I may be running into this problem, but I do not see any difference using the

Re: [sqlalchemy] group max, outerjoin, and subquery

2014-03-12 Thread Michael Bayer
On Mar 12, 2014, at 2:07 PM, Michael Weylandt michael.weyla...@gmail.com wrote: Hi Mike, I've simplified the query I'm looking for into a one line: (not sure why I didn't think of HAVING earlier -- definitely making a mountain from molehills) SELECT A.*, B1.*, C1.* FROM A LEFT OUTER

Re: [sqlalchemy] sql expression performance is bad ?

2014-03-12 Thread Ni Wesley
Just have a try. Move all operations upon session directly to engine.execute. Almost the same performance. How to improve? :-( 在 2014年3月12日星期三UTC+8下午9时35分08秒,Michael Bayer写道: On Mar 12, 2014, at 8:32 AM, Ni Wesley nis...@gmail.com javascript: wrote: Hi guys, I hit a problem

Re: [sqlalchemy] sql expression performance is bad ?

2014-03-12 Thread Michael Bayer
hows your SQL debug output and your profiling going? On Mar 12, 2014, at 9:56 PM, Ni Wesley nisp...@gmail.com wrote: Just have a try. Move all operations upon session directly to engine.execute. Almost the same performance. How to improve? :-( 在

Re: [sqlalchemy] sql expression performance is bad ?

2014-03-12 Thread Ni Wesley
I have not used cprofile before, but I enable engine echo and some logging, here is output: INFO:devsrv:httpMQ started... DEBUG:devsrv:Got connection from ('10.0.3.96', 62560) One device connected:('10.0.3.96', 62560) Connection

[sqlalchemy] Re: sql expression performance is bad ?

2014-03-12 Thread Ni Wesley
In case of network problem. I test in a vlan. Here is engine ouput and my logging: DEBUG:devsrv:Got connection from ('192.168.1.7', 63181) One device connected:('192.168.1.7', 63181) Connection