from sqlalchemy.dialects import postgresql query = ... print(str(query.compile(dialect=postgresql.dialect())))