Looker generating invalid nested with statements

We have an explore that is used by many of our analysts. While analyzing this object in the Explore section, we had an analyst receive an error after putting together a certain combination of fields. The error seems to be cause by the SQL code that Looker is generating for the Explore:

WITH outer_ce_name AS (with inner_cte as (

The second with clause is invalid here. I'm not sure how to debug this. The Explore works with many combinations of this field, but it doesn't work with at least this one.

Has anyone else experienced this?

0 1 23
1 REPLY 1

Hi @mmcilvride  —

Yes, this can happen if Looker generates nested CTEs (WITH blocks) incorrectly, often due to:

  • Derived tables (explore source) combining with table calculations

  • Custom measures or dimensions adding extra layers

To debug:

  • Check the LookML for any derived tables or SQL-based dimensions/measures involved.

  • Simplify the query: start with fewer fields, then add one by one to see which triggers the bad SQL.

  • If possible, review the generated SQL in the SQL tab to spot which field or join adds the nested WITH.

Top Labels in this Space
Top Solution Authors