Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Mike Bayer
On Sat, Aug 22, 2020, at 12:36 PM, Saakshaat Singh wrote: > I agree that it's not practical for saving columns with the same name but in > our case, we had to give the child subclasses the same column names. > SQLAlchemy has declared_attr >

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Mike Bayer
On Sat, Aug 22, 2020, at 12:33 PM, Saakshaat Singh wrote: > Thank you for looking into it Mike. I'll post an example today. > > But looking at your SQLAlchemy execution, I noticed that you're only passing > a value for the `child_value` field while the Parent class is polymorphic on > the

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Saakshaat Singh
I agree that it's not practical for saving columns with the same name but in our case, we had to give the child subclasses the same column names. SQLAlchemy has declared_attr which converts the columns to scalar

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Saakshaat Singh
Thank you for looking into it Mike. I'll post an example today. But looking at your SQLAlchemy execution, I noticed that you're only passing a value for the `child_value` field while the Parent class is polymorphic on the `ChildType` enum. So maybe it holds value to also pass values for the

Re: [sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Richard Damon
On 8/22/20 12:09 PM, Vitaly Kruglikov wrote: > Hi Richard. I wish it was that simple, but it's not. Here is an > example of how using a builtin name breaks: > > ``` > In [3]: unique = object() >    ...: class TestId: >    ...:     id = 'something else' >    ...:     unique_id = id(unique) >    

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Mike Bayer
If your model is based all on one table called "parent", it can only have one column called "child_value" and it can only be of a single database type, since that's your CREATE TABLE. I'm not able to follow what your example intends to do as you seem to be creating many Column objects with

Re: [sqlalchemy] ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Mike Bayer
changing the "key" of a column during reflection is not a process that's ever been supported before. you would be better off using a synonym here: from sqlalchemy.orm import Session, synonym _AutomapBase = automap.automap_base() class Model1(_AutomapBase): __tablename__ = "model1"

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Mike Bayer
Hi, I have no idea what the problem is and would need a fully runnable MCVE. Below is part of your test which I've tried to get running but it still errors out on identifiers missing and such, additionally I need a working example of exactly the session operations you are trying to achieve.

Re: [sqlalchemy] ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Mike Bayer
Hi Im not able to reproduce this, though I will grant things dont seem to work very well in this area, would need to know *exactly* what it is you are trying to accomplish. please alter the MCVE below to reproduce your error, it passes for me however does have a warning: from sqlalchemy import

Re: [sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Vitaly Kruglikov
Hi Richard. I wish it was that simple, but it's not. Here is an example of how using a builtin name breaks: ``` In [3]: unique = object() ...: class TestId: ...: id = 'something else' ...: unique_id = id(unique) ...: ...:

Re: [sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Richard Damon
On 8/22/20 10:46 AM, Vitaly Kruglikov wrote: > I suspect this has something to do with the combination of the > explicit definition of the `id_` column and reflection, but don't know > how to fix. I really need to keep the explicit `id_` descriptor and > shouldn't rename it to `id` because that's

[sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Vitaly Kruglikov
Please note, that I posted, then deleted a message with the same subject in order to correct some relevant information, and this post replaces the one I deleted. On Saturday, August 22, 2020 at 7:43:42 AM UTC-7 Vitaly Kruglikov wrote: > Dear all, > > I am using: > sqlalchemy==1.3.18 >

[sqlalchemy] ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Vitaly Kruglikov
Dear all, I am using: sqlalchemy==1.3.18 psycopg2==2.8.4 connection url schema: "postgresql+psycopg2://..." postgres 10.x My code looks like this: ``` _AutomapBase = automap.automap_base() class Model1(_AutomapBase): __tablename__ = 'model1" id_ = sa.Column('id', sa.Integer,