Created
February 4, 2014 13:29
-
-
Save sunpig/8803576 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import MetaData, create_engine, orm | |
from sqlalchemy.sql import select | |
engine = create_engine('postgresql+psycopg2://username:password@localhost:5432/dbname') | |
Session = orm.sessionmaker(bind=engine) | |
session = Session() | |
metadata = MetaData(bind=engine) | |
metadata.reflect() | |
table_1 = metadata.tables['table_1'] | |
table_1_column_1 = table_1.columns['column_1'] | |
labelled_column = table_1_column_1.label('my test column') | |
query = select([labelled_column]).select_from(table_1).order_by(labelled_column) | |
query = session.query(table_1).select(table_1_column_1) | |
str(query) # shows the SQL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment