sqlalchemy-timescaledb icon indicating copy to clipboard operation
sqlalchemy-timescaledb copied to clipboard

Support columns from an abstract table

Open dorosch opened this issue 1 year ago • 1 comments

Columns from an abstract table are not supported:

class Model(Base):
    __abstract__ = True

    created_at = Column(
        DateTime(timezone=True),
        nullable=False,
        default=datetime.datetime.now
    )

class Data(Model):
    __table_args__ = ({
        'timescaledb_hypertable': {
            'time_column_name': 'created_at'
        }
    })

Will trigger an exception:

sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions._base.UnknownPostgresError'>: cannot create a unique index without the column "created_at" (used in partitioning)
[SQL: 
            SELECT create_hypertable(
                'data',
                'created_at',
                chunk_time_interval => INTERVAL '7 days',
                if_not_exists => TRUE
            );
            ]
(Background on this error at: https://sqlalche.me/e/20/dbapi)

dorosch avatar Feb 26 '24 12:02 dorosch

I also encountered this problem. After searching the documentation, I set my column as primary key and this error disappeared.

image

MidCheck avatar Sep 11 '24 06:09 MidCheck