更新时间:2022-03-04 02:23:57
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')
这会创建一个新类型HybridType
,您可以像使用其他任何类型一样使用它,但要注意的是它将在Postgres上生成一个HSTORE
列,并在其他任何地方生成一个PickleType
.
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.