Re: [sqlalchemy] Abstract Table Concrete Inheritance. Could not determine join condition between parent/child tables

2017-05-15 Thread Никита Крокош
So, how should i do if I need many encumbrances for every cadastral object (flat.encumrances, building.encumbrances, ...etc). If I get it correctly, I need something like: class iCadastralObject(Base): __abstract__ = True def __init__(self, cadastral_region, cadastral_district,

Re: [sqlalchemy] Abstract Table Concrete Inheritance. Could not determine join condition between parent/child tables

2017-05-15 Thread mike bayer
when you use concrete inheritance, you now have three tables: building, flat, construction. If you'd like these to each have a relationship to iencumbrance, that's three separate foreign key constraints. Given the four-column primary key, you'd need to have twelve columns total on

[sqlalchemy] Abstract Table Concrete Inheritance. Could not determine join condition between parent/child tables

2017-05-15 Thread Никита Крокош
This is a duplicate from: http://stackoverflow.com/questions/43972912/abstract-table-concrete-inheritance-could-not-determine-join-condition-between I've got following example code: models.py class CadastralObject(Base): __tablename__ = 'cadastral_object' def __init__(self,

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

Re: [sqlalchemy] refresh's lockmode and with_for_update

2017-05-15 Thread mike bayer
On 05/15/2017 08:53 AM, Zsolt Ero wrote: Right now, the documentation for session.refresh() mentions: lockmode – Passed to the Query as used by with_lockmode()

[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

Re: [sqlalchemy] complex primary key with server_default timestamp

2017-05-15 Thread mike bayer
On 05/15/2017 06:43 AM, mdob wrote: Just curious. Let's say we have a complex primary key of user_id (integer), project_id (integer) and date (timestamp). After adding and committing we don't have the PK and we won't be able to update it. Is that right? if you were using Postgresql this

[sqlalchemy] refresh's lockmode and with_for_update

2017-05-15 Thread Zsolt Ero
Right now, the documentation for session.refresh() mentions: lockmode – Passed to the Query as used by with_lockmode()

[sqlalchemy] complex primary key with server_default timestamp

2017-05-15 Thread mdob
Just curious. Let's say we have a complex primary key of user_id (integer), project_id (integer) and date (timestamp). After adding and committing we don't have the PK and we won't be able to update it. Is that right? If it was auto-increment integer then it would probably be fine. PK would be