Skip to content

Instantly share code, notes, and snippets.

@sburns
Created December 10, 2014 15:07
Show Gist options
  • Save sburns/ed1226e3cd3d9d4c76d7 to your computer and use it in GitHub Desktop.
Save sburns/ed1226e3cd3d9d4c76d7 to your computer and use it in GitHub Desktop.
Print a literal SQLAlchemy statement
print(str(select.compile(engine, compile_kwargs={'literal_binds': True}))
@sburns
Copy link
Author

sburns commented Dec 10, 2014

This is only useful for testing select statements if, for instance, it's difficult to connect to a database in your development environment. Under no circumstances should you use this in production as you're opening yourself to SQL injection attacks one of the things binding protects against. Here we're directing sqlalchemy to literally bind values during statement compilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment