[sqlalchemy] How do Insert statements for single-table inheritance tables get batched together?

2017-10-09 Thread vineet
Hello! SQLAlchemy has the (really useful) behavior of batching together inserts when all the primary keys are defined. It looks like it groups similar tables together (while maintaining insert order ) to minimize the number of Insert statements sent to the database. I'm unsure what the

Re: [sqlalchemy] Batching INSERT statements

2017-10-09 Thread vineet
> > if you're using Postgresql, there's a vastly easier technique to use > which is just to pre-fetch from the sequence: > identities = [ > val for val, in session.execute( > "select nextval('mytable_seq') from " > "generate_series(1,%s)" % len(my_objects)) >

Re: [sqlalchemy] "execute(query)" behaving strangely

2017-10-09 Thread Colton Allen
You were exactly right. I needed to commit. On Monday, October 9, 2017 at 4:08:05 PM UTC-7, Mike Bayer wrote: > > On Mon, Oct 9, 2017 at 3:57 PM, Colton Allen > wrote: > > I'm trying to execute a fairly simple UPDATE query. > > > > query =

Re: [sqlalchemy] "execute(query)" behaving strangely

2017-10-09 Thread Mike Bayer
On Mon, Oct 9, 2017 at 3:57 PM, Colton Allen wrote: > I'm trying to execute a fairly simple UPDATE query. > > query = update(Model).where(Model.id.in_(list_of_ids)).values(x=1) > > I know of two methods to execute it. One using the session and the other > using the engine.

[sqlalchemy] Re: "execute(query)" behaving strangely

2017-10-09 Thread Colton Allen
Both are using postgres. But I did try updating the bind to both the engine (db.engine) and the session (db.session) and it didn't have any affect. On Monday, October 9, 2017 at 2:09:02 PM UTC-7, Jonathan Vanasco wrote: > > OTOMH (I didn't go through your code), are the two databases the same?

[sqlalchemy] Re: "execute(query)" behaving strangely

2017-10-09 Thread Jonathan Vanasco
OTOMH (I didn't go through your code), are the two databases the same? If not, this is possibly related to database specific compiling (or the lack of) and a common error. Note the `bind` references in the docs: http://docs.sqlalchemy.org/en/latest/core/tutorial.html#executing Depending on

[sqlalchemy] "execute(query)" behaving strangely

2017-10-09 Thread Colton Allen
I'm trying to execute a fairly simple UPDATE query. query = update(Model).where(Model.id.in_(list_of_ids)).values(x=1) I know of two methods to execute it. One using the session and the other using the engine. However, depending on which I use, the results I get are very different.

Re: [sqlalchemy] Batching INSERT statements

2017-10-09 Thread Mike Bayer
On Mon, Oct 9, 2017 at 4:15 AM, wrote: > Hello! I've spent some time looking at SQLAlchemy's ability to batch > inserts, and have a few questions about bulk_save_objects (and flushing in > general). > > Two statements that I think are true: > > Right now, bulk_save_objects

Re: [sqlalchemy] Postgres 10 identity keyword

2017-10-09 Thread Mike Bayer
On Sun, Oct 8, 2017 at 10:45 PM, Seth P wrote: > Apologies if I missed something, but does SQLAlchemy (1.2.0?) support the new > Postgres 10 identity keyword > (https://blog.2ndquadrant.com/postgresql-10-identity-columns/)? not directly, however you can intercept SERIAL and

[sqlalchemy] Batching INSERT statements

2017-10-09 Thread vineet
Hello! I've spent some time looking at SQLAlchemy's ability to batch inserts, and have a few questions about bulk_save_objects (and flushing in general). Two statements that I think are true: 1. Right now, bulk_save_objects does not fetch primary keys for inserted rows (unless