views:

534

answers:

3

Hello everybody

Is it possible to use raw SQL rather than the TABLE construct for creating tables in SQL Alchemy? I would still like to use the rest of SQLAlchemy though, such as the object mapper and session module. I'm just not fond of the SQLAlchemy syntax used to create tables (I've spent too long mired in SAS and SQL to learn another!).

Many thanks, Rich

+3  A: 

Yes.

connection.execute("""
CREATE TABLE ...
""")

You can then reflect all tables: MetaData(dsn, reflect=True) or metadata_instance.reflect().

Alex Brasetvik
A: 

SQLAlchemy doesn't create tables by default, you have to call some method (like MetaData.create_all()) explicitly.

Denis Otkidach
+1  A: 

You can use the autoload paramater to the Table constructor to have it automatically load up the table definitions. There are some examples here.

Noufal Ibrahim