Schedule - Nordic PGDay 2026

Structuring SQL: When and How

Date: 2026-03-24
Time: 11:15–12:05
Room: Vision 1
Level: Intermediate

Everyone familiar with object-oriented programming will be familiar with the concepts of decomposition (factoring) and encapsulation. OOP best practices dictate that code should be decomposed (or factored) into many smaller classes and objects responsible for a well-defined subset of system behavior, as well as encapsulated, restricting direct access to components and thus obscuring their implementation. These two principles make application code more readable and more manageable, and make it easier to make changes.

Coming from this paradigm, when one is confronted with a single SELECT statement of 500+ lines, it’s understandably tempting to apply these same principles, factoring the code into smaller pieces and encapsulating some of the logic. However, SQL’s declarative nature dictates a very different style of factoring SQL queries from what would be used with application code. The good news is that the SQL code could be kept easy to understand and modify without compromising performance.

In this talk, we will examine different ways of factoring and encapsulation in SQL and discuss their advantages and pitfalls.

Speaker

Henrietta Dombrovskaya