Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-16 Thread Zsolt Ero
Thanks a lot for the explanation, it's all clear now! On 15 May 2017 at 18:56, mike bayer wrote: > > > On 05/15/2017 11:56 AM, Zsolt Ero wrote: >> >> I might not be understanding something, but for me there are two >> different concepts here: >> >> map_obj =

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread mike bayer
On 05/15/2017 11:56 AM, Zsolt Ero wrote: I might not be understanding something, but for me there are two different concepts here: map_obj = dbsession.query(Map).get(id_) is an object in memory, loaded with a long SELECT statement, allowing us to get and set different attributes and the

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread Zsolt Ero
I might not be understanding something, but for me there are two different concepts here: map_obj = dbsession.query(Map).get(id_) is an object in memory, loaded with a long SELECT statement, allowing us to get and set different attributes and the session / transaction manager commits the

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread mike bayer
On 05/15/2017 10:54 AM, Zsolt Ero wrote: Thanks, it is all clear now. Just out of interest, what is the point of synchronize_session='fetch'? that will do a SELECT and get the new value back and update your ORM object in memory. Set synchronize_session=False if you don't care. For me

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread Jonathan Vanasco
On Monday, May 15, 2017 at 9:58:57 AM UTC-4, Mike Bayer wrote: > > I'd be curious to see under what scenarios being able to set one element > of the JSON > vs. UPDATEing the whole thing is a performance advantage significant > compared to the usual overhead of the ORM flush process; that is,

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread Zsolt Ero
Thanks, it is all clear now. Just out of interest, what is the point of synchronize_session='fetch'? For me all it does is a simple SELECT maps.id AS maps_id FROM maps WHERE maps.id = %(id_1)s All I get as a return value is 0: not successful (probably id didn't exist), while 1: successful. It is

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread mike bayer
On 05/15/2017 10:31 AM, Zsolt Ero wrote: I'm trying to run your example, but it doesn't work: from sqlalchemy import func m = request.dbsession.query(models.Map).get(3) m.screenshots = func.jsonb_set(m.screenshots, '{key}', '"value"') request.dbsession.flush() It ends up in a

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread mike bayer
On 05/15/2017 10:18 AM, Zsolt Ero wrote: Thanks for the answer. My use case is the following: I have an object (map_obj), which has screenshots in two sizes. I'm using JSONB columns to store the screenshot filenames. Now, the two screenshot sizes are generated in parallel. The code is like

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread Zsolt Ero
I'm trying to run your example, but it doesn't work: from sqlalchemy import func m = request.dbsession.query(models.Map).get(3) m.screenshots = func.jsonb_set(m.screenshots, '{key}', '"value"') request.dbsession.flush() It ends up in a (psycopg2.ProgrammingError) can't adapt type 'dict'. Also,

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread Zsolt Ero
Thanks for the answer. My use case is the following: I have an object (map_obj), which has screenshots in two sizes. I'm using JSONB columns to store the screenshot filenames. Now, the two screenshot sizes are generated in parallel. The code is like the following: map_obj = query(...by id...)

Re: [sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread mike bayer
On 05/15/2017 09:32 AM, Zsolt Ero wrote: In PostgreSQL 9.5+ it is finally possible to modify a single key inside a JSONB column. Usage is something like this: update maps set screenshots=jsonb_set(screenshots, '{key}', '"value"') where id = 10688 Is it possible to write this query using

[sqlalchemy] jsonb_set in PostgreSQL 9.5+

2017-05-15 Thread Zsolt Ero
In PostgreSQL 9.5+ it is finally possible to modify a single key inside a JSONB column. Usage is something like this: update maps set screenshots=jsonb_set(screenshots, '{key}', '"value"') where id = 10688 Is it possible to write this query using the ORM somehow? If not, please take it as a