Generic TEXT/CLOB data type for cross-database SQLAlchemy application

database, python, sqlalchemy

Solution

According to @agronholm on #sqlalchemy one is supposed to use generic SQLAlchemy type `Text` (which `TEXT` is specialization of):

A variably sized string type.

In SQL, usually corresponds to CLOB or TEXT. Can also take Python unicode objects and encode to the database’s encoding in bind params (and the reverse for result sets.) In general, TEXT objects do not have a length; while some databases will accept a length argument here, it will be rejected by others.

Problem

I am working on Python web application that uses MySQL as a database backend on the development environment and Oracle 11g on the production environment. Is there a specific way to unify the SQLAlchemy text fields, so that they work both on MySQL and Oracle database? For the Oracle backend in the models I use `sqlalchemy.CLOB` and for MySQL `sqlalchemy.TEXT`.

Original source