Created
August 13, 2015 09:41
-
-
Save aodag/043da0cc1a9c822abd81 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.sql.expression import table, column | |
>>> from sqlalchemy.sql.expression import select | |
>>> from sqlalchemy.sql.types import VARCHAR | |
>>> from sqlalchemy.dialects.postgresql import dialect | |
>>> employee = table('employee', column('id', VARCHAR), column('job_id', VARCHAR)) | |
>>> job = table('job', column('id', VARCHAR), column('name', VARCHAR)) | |
>>> str(select([employee.join(job, employee.c.job_id == job.c.id)]).compile(dialect=dialect())) | |
'SELECT employee.id, employee.job_id, job.id, job.name \nFROM employee JOIN job ON employee.job_id = job.id' | |
>>> stmt = select([employee.join(job, employee.c.job_id == job.c.id)]).where(job.c.name == 'programmer') | |
>>> str(stmt.compile(dialect=dialect())) | |
'SELECT employee.id, employee.job_id, job.id, job.name \nFROM employee JOIN job ON employee.job_id = job.id \nWHERE job.name = %(name_1)s' | |
>>> stmt.compile(dialect=dialect()).params | |
{u'name_1': 'programmer'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment