The Curated Daily
← Back to the archiveDispatch · 6 min read
Dispatch

What ORMs have taught me: just learn SQL (2014)

By the editors·Sunday, July 5, 2026·6 min read
Colleagues discussing data trends on a whiteboard with graphs and charts.
Photograph by www.kaboompics.com · Pexels

For years, I’ve navigated the world of financial data – modeling portfolios, building risk management systems, and analyzing trading strategies. And for a significant portion of that time, I relied heavily on Object-Relational Mappers (ORMs). These tools promised to shield me from the complexities of SQL, allowing me to interact with databases using the familiar syntax of my chosen programming language (mostly Python, in my case). But somewhere along the line, I hit a wall. A wall built not of technical limitations, but of understanding. I realized that the core skill wasn't wielding the ORM; it was understanding the underlying SQL.

This isn't a dismissal of ORMs entirely. They have their place. But for anyone serious about working with data, especially in a demanding field like finance, prioritizing SQL is paramount. This article details my journey, the lessons I learned, and why you should focus your efforts on becoming proficient in SQL.

The Allure of the ORM

Let’s start by acknowledging the appeal of ORMs. They offer several advantages, at least on the surface.

  • Abstraction: ORMs abstract away the database-specific syntax, allowing for greater portability between database systems (PostgreSQL, MySQL, SQL Server, etc.).
  • Object-Oriented Paradigm: They let you work with data as objects, which feels more natural for developers accustomed to object-oriented programming.
  • Reduced Boilerplate: They eliminate the need to write repetitive SQL queries for basic CRUD (Create, Read, Update, Delete) operations.
  • Security: Some ORMs offer built-in protection against SQL injection vulnerabilities.

These benefits are compelling, especially when starting a project. I initially embraced ORMs like SQLAlchemy in Python with open arms. They seemed to streamline development, reduce errors, and allow me to focus on the "business logic" rather than the "plumbing."

The Cracks Begin to Show (In Finance, Of All Places)

The problems started subtly. Simple queries were fine. But as the complexity of the financial models I was building increased, the ORM’s limitations became painfully obvious. Finance is a domain characterized by:

  • Complex Relationships: Portfolio holdings, trade histories, market data – all interconnected in intricate ways. Modeling these accurately requires sophisticated joins and subqueries.
  • Performance Sensitivity: Real-time risk calculations and high-frequency trading algorithms demand lightning-fast query execution. ORM-generated SQL often isn’t optimized for performance.
  • Data Integrity: Financial data must be accurate. Understanding how data is stored and retrieved is critical for ensuring data quality.
  • Ad-hoc Analysis: Unexpected market events often necessitate quick, custom queries to analyze the impact on portfolios. ORMs aren't always flexible enough for this.

I found myself constantly fighting the ORM to achieve the performance I needed. I’d spend hours debugging generated SQL, trying to understand why a seemingly simple query was taking minutes to execute. The abstraction, once a blessing, became a curse. I was debugging the ORM's interpretation of my intent, not the actual query itself.

The Debugging Nightmare: Understanding the Generated SQL

The biggest issue wasn't necessarily that ORMs couldn’t handle complex queries. It was that diagnosing why they were slow, or even incorrect, was incredibly difficult. Here’s a typical scenario:

  1. I’d write an ORM query to retrieve data for a specific portfolio’s performance attribution.
  2. The application would grind to a halt.
  3. I’d have to enable logging to see the SQL the ORM had generated.
  4. The generated SQL would be a monstrous, convoluted mess, riddled with joins and subqueries.
  5. I’d then spend the next hour deciphering the SQL, trying to identify the bottleneck.

This process was not only time-consuming but also frustrating. I was essentially learning SQL through the lens of a poorly optimized query. It was like trying to learn a language by reading a badly translated book.

The Power of Knowing SQL

Once I shifted my focus to learning SQL directly, things began to change dramatically.

  • Direct Control: I could write queries that were precisely optimized for the task at hand, leveraging database-specific features and indexing strategies.
  • Faster Debugging: I could immediately identify performance bottlenecks and errors in the SQL itself, without having to wade through layers of abstraction.
  • Improved Data Understanding: The act of writing SQL forced me to think deeply about the data model and the relationships between different tables.
  • Greater Flexibility: I could easily perform ad-hoc analysis and respond quickly to changing requirements.
  • Better Code Reviews: Understanding SQL makes you a much better code reviewer, enabling you to quickly spot inefficient or incorrect queries in others’ code.

I started using tools like https://example.com/ (a popular SQL editor and database management tool) to experiment with different query formulations and analyze execution plans. Understanding execution plans – how the database engine actually executes a query – was a game-changer.

When ORMs Still Make Sense

I'm not suggesting you abandon ORMs altogether. They remain useful in certain situations.

  • Simple CRUD Operations: For basic data access, ORMs can save you time and effort.
  • Rapid Prototyping: When you're quickly building a proof-of-concept, an ORM can help you get up and running faster.
  • Small Projects: If your database interactions are relatively simple, the overhead of learning SQL may not be justified.

However, even in these cases, I recommend maintaining a solid understanding of the underlying SQL. This will allow you to diagnose problems when they arise and optimize your queries as your application grows.

Prioritize These SQL Concepts for Finance

If you’re working in finance and want to level up your data skills, focus on these SQL concepts:

  • Joins: Master inner, left, right, and full outer joins. Understanding how to join tables efficiently is crucial for working with complex financial data.
  • Subqueries: Learn how to use subqueries to filter and aggregate data.
  • Window Functions: Window functions are incredibly powerful for calculating moving averages, rankings, and other time-series metrics commonly used in finance.
  • Common Table Expressions (CTEs): CTEs make complex queries more readable and maintainable.
  • Indexing: Understanding how indexes work is essential for optimizing query performance. Knowing which columns to index can make a massive difference.
  • Transactions: Essential for ensuring data consistency when performing multiple operations.
  • Stored Procedures (depending on your database): Can be useful for encapsulating complex logic and improving performance.

Here's a quick reference table:

| SQL Concept | Use Case in Finance |

|---------------------|--------------------------------------------------------| | Joins | Linking trades to portfolios, market data to holdings. | | Window Functions | Calculating rolling returns, risk metrics. | | CTEs | Breaking down complex portfolio calculations. | | Indexing | Speeding up queries for real-time risk reporting. | | Transactions | Ensuring accurate trade settlements. |

Resources for Learning SQL

There's a wealth of resources available for learning SQL. Here are a few to get you started:

Final Thoughts

My experience with ORMs taught me a valuable lesson: don't let tools abstract away your fundamental understanding. While ORMs can be helpful in certain situations, they should never be a substitute for a solid grasp of SQL. In the fast-paced, data-driven world of finance, SQL is not just a skill; it’s a superpower. Invest the time to learn it well, and you’ll be able to unlock the full potential of your data.

Disclaimer

Affiliate Disclosure: This article contains affiliate links (marked as https://example.com/). If you purchase a product through these links, I may earn a small commission at no extra cost to you. This helps support the creation of valuable content like this. I only recommend products I believe in and have found useful.

Pass it onX·LinkedIn·Reddit·Email
The Sunday note

If this was your kind of read.

Sign up for the morning email — short, hand-written, and sent only when there's something worth your time.

Free, sent from a person, not a system. Unsubscribe in one click whenever.

Keep reading

The archive →