Fixing SQL Spaghetti : Effective Refactoring Techniques

Publicado em: 01 Janeiro 1970
no canal de: MotherDuck
1,083
30

In this episode, Lindsay and Mehdi will tackle a big challenge for data professionals: dealing with old SQL scripts. How can we make messy SQL code easier to read and maintain? We'll discuss pragmatics things you can do, and we'll tackle an ugly SQL script refactoring 😱

--------------------------------------

In this episode of Quack and Code, we tackle the dreaded "SQL spaghetti"—long, messy SQL scripts that are hard to maintain. Joined by Lindsey Murphy, Head of Data at Sakoda, we explore practical solutions for SQL refactoring. Lindsey shares her experience as a "data team of one," managing everything from infrastructure and dbt projects to stakeholder prioritization, offering valuable insights for data professionals in similar full-stack data roles. We also touch on the current AI hype cycle and its impact on data team roadmaps.

We discuss the key triggers for a SQL refactor, such as a data warehouse migration from Postgres to Snowflake or tackling performance bottlenecks that slow down your entire data pipeline. Refactoring isn't just about SQL optimization; it’s about improving code readability and documentation to increase team velocity, especially when onboarding new members. We cover the challenges of understanding business context and data collection nuances—a critical step where you must play detective, as the original query author may no longer be around.

Learn actionable SQL refactoring techniques and dbt best practices. We demonstrate how to make your code more readable and maintainable by breaking down nested subqueries into well-named Common Table Expressions (CTEs). A key strategy is to avoid changing business logic while refactoring; focus on one thing at a time, whether it's structure or formatting. Using tools like SQLFluff helps enforce consistent SQL formatting across your team, a crucial step for maintainability.

Discover how to structure your transformations using dbt modeling layers (staging, intermediate, and marts) to create a clean, understandable data flow. We show you how to set up an efficient local development environment with DuckDB, allowing you to generate large TPC-H datasets and iterate on your refactoring without incurring cloud costs. This hands-on approach, combined with dbt's powerful testing features, ensures you can validate your changes and confidently improve your data models.

Watch with full transcript & resources: https://motherduck.com/videos/fixing-...


Nesta página do site você pode assistir ao vídeo on-line Fixing SQL Spaghetti : Effective Refactoring Techniques duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário MotherDuck 01 Janeiro 1970, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,083 vezes e gostou 30 espectadores. Boa visualização!