3 ms·
> It's really not an easy task to decipher complex SQLAlchemy expression back into SQL SQLAlchemy to SQL is borderline trivial, you just call `str(statement)`
by nick238 3y ago
> It's really not an easy task to decipher complex SQLAlchemy expression back into SQL
SQLAlchemy to SQL is borderline trivial, you just call `str(statement)` and it will output SQL. [Here's the docpage for if you want to select dialects and optionally inline parameters](https://docs.sqlalchemy.org/en/20/faq/sqlexpressions.html#how-do-i-render-sql-expressions-as-strings-possibly-with-bound-parameters-inlined https://docs.sqlalchemy.org/en/20/faq/sqlexpressions.html#ho...).
- tda 3y agoYes, but to get the exact query with interpolated parameters that can be copy pasted into e.g. pgadmin for a nice explain analyze visualization is a bit more involved. As I could never remember it I always copy pasted that function in any project. But other than that minor complaint I have always been thoroughly impressed by both SQLAlchemy ORM and the Core query builder, and how they can be combined to have a best of both worlds situation. I have written some very complex queries that remained maintainable thanks to composition with cte's, sub queries and computed properties. Doing that in pure SQL would also have been possible, but using using SQLlachemy allowed me to name and reuse smaller components, avoiding the wall of text SQL statements.
- deleted 3y ago[deleted]