[sqlalchemy] Re: How to query data from a relational table according to a list of matched conditions?

2009-12-22 Thread Olli Wang
Thanks for reply. I finally got the right result as following: for article in session.query(Article, func.count(Article.id).label ('count')) \ .join(Article.keywords).group_by(Article.name) \ .filter(Keyword.name.in_(['k2', 'k3', 'k6', 'k7'])).order_by('count DESC'):

Re: [sqlalchemy] Extending mapper to use PostgreSQL's INSERT/UPDATE...RETURNING

2009-12-22 Thread Michael Bayer
On Dec 22, 2009, at 5:20 PM, Igor Katson wrote: >> 0.5 supports this using the "postgres_returning" argument to update() and >> insert(), but the ORM doesn't make use of it. in 0.6, the feature has been >> generalized using the returning() method on insert() and update(), and the >> ORM will

Re: [sqlalchemy] Extending mapper to use PostgreSQL's INSERT/UPDATE...RETURNING

2009-12-22 Thread Michael Bayer
On Dec 22, 2009, at 2:51 PM, Igor Katson wrote: > > I am concerned about the problem of the orm framework using SELECT's a > lot, which can be not used in many cases, when dealing with Postgres > after INSERTs or UPDATEs. on this point specifically, when a SQL expression is used to generate t

Re: [sqlalchemy] Extending mapper to use PostgreSQL's INSERT/UPDATE...RETURNING

2009-12-22 Thread Igor Katson
Michael Bayer wrote: > On Dec 22, 2009, at 2:51 PM, Igor Katson wrote: > > >> I am concerned about the problem of the orm framework using SELECT's a >> lot, which can be not used in many cases, when dealing with Postgres >> after INSERTs or UPDATEs. >> >> When using postgresql, I want sqlalche

Re: [sqlalchemy] injecting explain analyze into ORM queries?

2009-12-22 Thread Michael Bayer
On Dec 21, 2009, at 7:40 PM, kris wrote: > Is it possible to turn on explain analyze during query execution.. I > have some slow queries > and it would be very useful if we could simply enable analysis at > runtime. nothing built in for this - I generally use engine logging or Postgresql loggin

Re: [sqlalchemy] Detach a Session from threadlocal behaviour

2009-12-22 Thread Igor Katson
Michael Bayer wrote: > On Dec 22, 2009, at 3:03 PM, Igor Katson wrote: > > >> Hi, >> >> when a request comes into my webapp, pylons makes a shiny new >> threadlocal Session for this request (thread), and it's perfectly fine. >> However, after returning the result to the client, I want to be abl

Re: [sqlalchemy] Detach a Session from threadlocal behaviour

2009-12-22 Thread Michael Bayer
On Dec 22, 2009, at 3:03 PM, Igor Katson wrote: > Hi, > > when a request comes into my webapp, pylons makes a shiny new > threadlocal Session for this request (thread), and it's perfectly fine. > However, after returning the result to the client, I want to be able to > continue processing in a

Re: [sqlalchemy] How to query data from a relational table according to a list of matched conditions?

2009-12-22 Thread Michael Bayer
On Dec 22, 2009, at 1:39 AM, Olli Wang wrote: > Hi, is it possible to query data from a relational table according to > a list of matched conditions? For example, assume I have two tables, > Article and Keywords, in a Many-to-Many relationship, and have data > like this: > > Article 1 has keywor

Re: [sqlalchemy] Output/Update Current Schema?

2009-12-22 Thread Michael Bayer
On Dec 21, 2009, at 9:05 PM, Nick Retallack wrote: > Say you've created some models in SQLAlchemy, and run create_all() to > get them into the database. Later on, you changed some of their > definitions, and you need to update the database schema to correspond > to it. How would you do this? C

Re: [sqlalchemy] Extending mapper to use PostgreSQL's INSERT/UPDATE...RETURNING

2009-12-22 Thread Michael Bayer
On Dec 22, 2009, at 2:51 PM, Igor Katson wrote: > > I am concerned about the problem of the orm framework using SELECT's a > lot, which can be not used in many cases, when dealing with Postgres > after INSERTs or UPDATEs. > > When using postgresql, I want sqlalchemy, when updating the instanc

Re: [sqlalchemy] Re: Multiple table query ?

2009-12-22 Thread Mariano Mara
Excerpts from gsandorx's message of Tue Dec 22 16:03:44 -0300 2009: > Hi Mariano, I tried your code and it worked great. Now I have to look > a way of linking the "union" query with a mapper to obtain a rather > elaborate object than a raw tuple, I mean, when you execute: > q = session.query(Comput

[sqlalchemy] Detach a Session from threadlocal behaviour

2009-12-22 Thread Igor Katson
Hi, when a request comes into my webapp, pylons makes a shiny new threadlocal Session for this request (thread), and it's perfectly fine. However, after returning the result to the client, I want to be able to continue processing in a separate thread, but not use another session (another db con

[sqlalchemy] Extending mapper to use PostgreSQL's INSERT/UPDATE...RETURNING

2009-12-22 Thread Igor Katson
Hi, when I started using code like obj.column = obj.column + 1, which I had to make through raw sql (because in SQL e.g. "update...set column = 400 + 1" is not equal to "update...set column = column + 1", when many threads do this concurrently), I faced a problem, that to update the value and

[sqlalchemy] Re: Multiple table query ?

2009-12-22 Thread gsandorx
Hi Mariano, I tried your code and it worked great. Now I have to look a way of linking the "union" query with a mapper to obtain a rather elaborate object than a raw tuple, I mean, when you execute: q = session.query(Computer).all() you get Computer objects, but when you execute the "union" query y

Re: [sqlalchemy] ArgumentError: Only '='/'!=' operators can be used with NULL

2009-12-22 Thread jo
Mike Conley wrote: > On Tue, Dec 22, 2009 at 2:34 AM, jo > wrote: > > Hi all, > > I'm trying to solve this error... > > File > "/home/sfera/release/sicer/BASE/controller/controlli/sopralluogo.py", > line 645, in verifiche > Piano.c.data_in

Re: [sqlalchemy] ArgumentError: Only '='/'!=' operators can be used with NULL

2009-12-22 Thread Mike Conley
On Tue, Dec 22, 2009 at 2:34 AM, jo wrote: > Hi all, > > I'm trying to solve this error... > > File > "/home/sfera/release/sicer/BASE/controller/controlli/sopralluogo.py", > line 645, in verifiche > Piano.c.data_inizio <=data.get('data_sop') , > File "/usr/lib/python2.4/site-packages/sqlalchemy/s

[sqlalchemy] ArgumentError: Only '='/'!=' operators can be used with NULL

2009-12-22 Thread jo
Hi all, I'm trying to solve this error... File "/home/sfera/release/sicer/BASE/controller/controlli/sopralluogo.py", line 645, in verifiche Piano.c.data_inizio <=data.get('data_sop') , File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 1294, in __le__ return self._compare('<=', ot