[sqlalchemy] Set query timeout

2016-12-01 Thread Антонио Антуан
Hi Is there any ways to set timeout for particular query, instead of the whole session/connection? Thanks -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example.

Re: [sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread mike bayer
On 12/01/2016 11:49 AM, Adrian wrote: `from_self().exists()` seems to produce an unnecessarily complex query (still containing all the original columns) also please see the source for count() re: the original columns: col = sql.func.count(sql.literal_column('*')) return

Re: [sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread mike bayer
On 12/01/2016 11:49 AM, Adrian wrote: `from_self().exists()` seems to produce an unnecessarily complex query (still containing all the original columns) it is unnecessarily complex in some situations but in others it is not. count() for many years tried to guess which situations it could

Re: [sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread Adrian
`from_self().exists()` seems to produce an unnecessarily complex query (still containing all the original columns) -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable

Re: [sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread mike bayer
if it works like count(), then it would be making use of from_self() which disables eager loads already. On 12/01/2016 09:47 AM, Adrian wrote: Would you be interested in a PR adding `Query.row_exists()` or even `Query.row_exists(disable_eagerloads=True)` which would also disable eagerloads by

Re: [sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread Adrian
Would you be interested in a PR adding `Query.row_exists()` or even `Query.row_exists(disable_eagerloads=True)` which would also disable eagerloads by default? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide

Re: [sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread mike bayer
On 12/01/2016 09:37 AM, Adrian wrote: I would normally do session.query(Foo).count() COUNT is somewhat expensive compared to just checking whether rows exist, especially if lots of rows match (2.2M rows in the example): I would have assumed you had some filtering condition. Checking an

Re: [sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread Adrian
> I would normally do session.query(Foo).count() COUNT is somewhat expensive compared to just checking whether rows exist, especially if lots of rows match (2.2M rows in the example): In [2]: %timeit -n1 -r1 EventPerson.query.count() 1 loop, best of 1: 135 ms per loop In [3]: %timeit -n1 -r1

Re: [sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread mike bayer
On 12/01/2016 09:13 AM, Adrian wrote: Is there any shorter/prettier way for this? session.query(session.query(Foo).exists()).scalar() I would normally do session.query(Foo).count() I've never embedded an EXISTS like that. It's not hard to add a custom method to the base query

[sqlalchemy] Shortcut for session.query(somequery.exists()).scalar()

2016-12-01 Thread Adrian
Is there any shorter/prettier way for this? session.query(session.query(Foo).exists()).scalar() It's not hard to add a custom method to the base query class that returns self.session.query(self.exists()).scalar() but it feels like something that should be part of SQLAlchemy. Also, is