I want to use HSTORE type for a column if it uses PostgreSQL as its backend, or PickleType otherwise. The problem is that we cannot determine which backend will be used when sc
You can accomplish something like this with TypeEngine.with_variant:
from sqlalchemy.types import PickleType
from sqlalchemy.dialects import postgresql
HybridType = PickleType()
HybridType = HybridType.with_variant(postgresql.HSTORE(), 'postgresql')
This creates a new type, HybridType
, which you can use like any other type, with the caveat that it will produce an HSTORE
column on Postgres and a PickleType
everywhere else.