Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-17 Thread Mike Bayer
On Mon, Jun 17, 2019, at 12:02 PM, João Miguel Neves wrote: > Hi, > > Ok, versioning adds a different requirement level, as it fails if the version > being updated has changed. I was looking for a situation where updating 2 > keys inside a JSONB field wouldn't lose one of them. Using

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-17 Thread Mike Bayer
On Mon, Jun 17, 2019, at 12:02 PM, João Miguel Neves wrote: > Hi, > > Ok, versioning adds a different requirement level, as it fails if the version > being updated has changed. I was looking for a situation where updating 2 > keys inside a JSONB field wouldn't lose one of them. Using

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-17 Thread João Miguel Neves
Hi, Ok, versioning adds a different requirement level, as it fails if the version being updated has changed. I was looking for a situation where updating 2 keys inside a JSONB field wouldn't lose one of them. Using versioning it raises an exception when writing one of them (which is better than

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread João Miguel Neves
Cool, wasn't aware of that feature! Thanks! On Fri, Jun 14, 2019 at 5:50 PM Mike Bayer wrote: > > > On Fri, Jun 14, 2019, at 12:46 PM, Mike Bayer wrote: > > > > On Fri, Jun 14, 2019, at 12:22 PM, João Miguel Neves wrote: > > Not performance, actually to avoid a race condition with key/values >

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread Mike Bayer
On Fri, Jun 14, 2019, at 12:46 PM, Mike Bayer wrote: > > > On Fri, Jun 14, 2019, at 12:22 PM, João Miguel Neves wrote: >> Not performance, actually to avoid a race condition with key/values written >> to JSONB fields. Ended up with the following function that we use for when >> multiple

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread Mike Bayer
On Fri, Jun 14, 2019, at 12:22 PM, João Miguel Neves wrote: > Not performance, actually to avoid a race condition with key/values written > to JSONB fields. Ended up with the following function that we use for when > multiple updates at the same time can occur (from the frontend mostly). It's

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread João Miguel Neves
Not performance, actually to avoid a race condition with key/values written to JSONB fields. Ended up with the following function that we use for when multiple updates at the same time can occur (from the frontend mostly). It's based on your recommendations from

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread Mike Bayer
On Fri, Jun 14, 2019, at 11:49 AM, João Miguel Neves wrote: > Hi Mike, > > Thank you very much for the quick response! > > Is there any other way to find the right table from the model other than > somthing like Engineer.name.property.columns[0].table? (I'm trying to do an > update in a

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread João Miguel Neves
Hi Mike, Thank you very much for the quick response! Is there any other way to find the right table from the model other than somthing like Engineer.name.property.columns[0].table? (I'm trying to do an update in a codepath that can have several different models passed to it) TIA, João On Fri,

Re: [sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread Mike Bayer
On Fri, Jun 14, 2019, at 10:30 AM, João Miguel Neves wrote: > Hi, > > I have a situation where an update tries to update the wrong table on when a > column comes from the parent table and is not on the current table. I'll > grant I didn't quite understand all the caveats in >

[sqlalchemy] Issue with bulk updates on ORM and PostgreSQL

2019-06-14 Thread João Miguel Neves
Hi, I have a situation where an update tries to update the wrong table on when a column comes from the parent table and is not on the current table. I'll grant I didn't quite understand all the caveats in https://docs.sqlalchemy.org/en/13/orm/query.html#sqlalchemy.orm.query.Query.update so