Announcing a New Primer: LookML for SQL Experts

Gemini_Generated_Image_9l4wi89l4wi89l4w.jpeg

In the 40+ years that relational databases have been around, Structured Query Language (SQL) has remained the standard way to query and manipulate data. SQL has withstood the test of time. No proposal to replace SQL has made it out of a niche usage. However, SQL presents a challenge when it comes to code reusability.

One of the core adages of programming is “Don't repeat yourself.” This dictum does not translate into the world of SQL very well. For example, imagine that you need to decode transaction codes by using a SQL CASE statement across multiple queries. Ideally, you would write some code as a reusable component – call it something like DECODE_TRANSACTION -  and then use it over and over again in SQL. While basic SQL is fairly consistent across dialects, advanced features like functions and procedures can vary significantly. (Sometimes these features aren’t even supported.) Additionally, if the SQL CASE is written out, the query optimizer might use some optimization paths that aren’t available if the same logic is inside a function. In the end, that complex SQL CASE is simply reused by copy and paste. A change in definition or logic means searching the entire codebase, finding all the instances where that expression is used, modifying it, and testing the entire thing.

LookML - Looker’s modeling language - is designed to remedy this problem by allowing SQL expressions to be written once and used by reference. Looker assembles these fragments of SQL in the LookML into proper SQL statements, eliminating the need  for repeated declarations. 

Proficiency with LookML is achieved by breaking apart SQL queries and seeing how the SQL expressions are modeled in LoomML. To help with this, we’ve added a LookML for SQL experts section to the Looker documentation. These pages are written for someone who already has a fair bit of experience with SQL, and explains LookML elements as they relate to SQL:

We have also posted a page to the Looker Community:

Version history
Last update:
‎10-02-2024 03:39 PM
Updated by: