Re: [sqlalchemy] Entity name - multiple schema - relationship

2014-05-08 Thread Julien Meyer
Thank you very much for your advice. Le mardi 6 mai 2014 17:21:55 UTC+2, Michael Bayer a écrit : set_shard is a special method added by the horizontal sharding extension. you can do cross schema queries if you organize the schema names in terms of which ones apply to the “dynamic” shard

[sqlalchemy] Nested select from insert into select union select

2014-05-08 Thread gbr
I don't quite understand why SQLA generates this query. For some reason it wraps the union part into a separate select. How can I avoid this? b_id = 2 s_id = 3 id = product.c.id sel = select( [b_id, product.c.id], ).union( select([b_id, s_id]) ) ins = insert(product).from_select([

[sqlalchemy] Threading Queries

2014-05-08 Thread James Meneghello
A couple of questions: I'm writing an application using concurrent.futures (by process). The processes themselves are fairly involved - not simple functions. I'm using scoped_sessions and a context manager like so: # db.py engine = create_engine(sqlalchemy_url) Session =

[sqlalchemy] Triggers with sqlite

2014-05-08 Thread Joseph Casale
For a trigger template something like: trg_template = CREATE TRIGGER trg_foo_{0} AFTER {0} ON foo FOR EACH ROW BEGIN ... END; Why does the following not work to remove some redundant boiler plate code: for x in 'UPDATE', 'INSERT', 'DELETE': event.listen(

Re: [sqlalchemy] Triggers with sqlite

2014-05-08 Thread Simon King
On Thu, May 8, 2014 at 5:37 PM, Joseph Casale jcas...@gmail.com wrote: For a trigger template something like: trg_template = CREATE TRIGGER trg_foo_{0} AFTER {0} ON foo FOR EACH ROW BEGIN ... END; Why does the following not work to remove some redundant boiler

Re: [sqlalchemy] Triggers with sqlite

2014-05-08 Thread Joseph Casale
You've been bitten by a Python gotcha! http://docs.python-guide.org/en/latest/writing/gotchas/#late-binding-closures Ugh, thanks Simon, moment of careless haste in thinking about this. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To

[sqlalchemy] Improving a subquery

2014-05-08 Thread Joseph Casale
I have scenario where I have a TableA that contains rows with with an optional reference to TableB. That foreign key column in TableA has triggers and constraints enforcing either one null or many with unique references. When I query for rows I need to select either rows with a reference that

Re: [sqlalchemy] Improving a subquery

2014-05-08 Thread Michael Bayer
this kind of thing is achieved with an OUTER JOIN. you can put everything to do with TableB and the join into the ON clause: session.query(TableA).outerjoin(TableB, and_(TableA.col_fk_id == TableB.col, TableB.col == 1)) On May 8, 2014, at 2:32 PM, Joseph Casale jcas...@gmail.com wrote: I

Re: [sqlalchemy] Nested select from insert into select union select

2014-05-08 Thread Michael Bayer
this can't be avoided right now as the insert from select feature checks the incoming object as a Select, which a UNION is not; it then calls select() on that union. a lot of databases have trouble with a raw UNION like that, we can loosen this restriction to apply to union-orinented selects

Re: [sqlalchemy] Threading Queries

2014-05-08 Thread Michael Bayer
On May 8, 2014, at 5:06 AM, James Meneghello murod...@gmail.com wrote: A couple of questions: I'm writing an application using concurrent.futures (by process). The processes themselves are fairly involved - not simple functions. I'm using scoped_sessions and a context manager like so:

Re: [sqlalchemy] Nested select from insert into select union select

2014-05-08 Thread gbr
So what can I do? I'm using postgres 9.3 The error message I get is: ProgrammingError: (ProgrammingError) subquery in FROM must have an alias LINE 2: FROM (SELECT 2, product_id ^ HINT: For example, FROM (SELECT ...) [AS] foo. Adding `sel = sel.alias()` doesn't do anything

Re: [sqlalchemy] Nested select from insert into select union select

2014-05-08 Thread Michael Bayer
OK well https://bitbucket.org/zzzeek/sqlalchemy/issue/3044/insert-from-select-union has a patch, that's what we'll be doing. a workaround might be to monkeypatch select() for now: sel = select( [b_id, product.c.id], ).union( select([b_id, s_id]) ) sel.select = lambda : sel On May