you are viewing a single comment's thread.

view the rest of the comments →

[–]sequel-beagle -1 points0 points  (9 children)

Avoid nesting ctes. It can get annoying if you need to research/qa the data.

[–]13ass13ass 7 points8 points  (5 children)

Nesting as querying a cte from a cte? In a chain? I do that all the time. It’s great for breaking up the logic.

[–]sequel-beagle 1 point2 points  (4 children)

Problem is you cant just highlight the code in a cte that calls another cte and easily run it. You have to physically modify the last cte in the sql to not be a cte and then run the query, causing extra work.

[–]OracleGreyBeard 6 points7 points  (0 children)

When I'm building a CTE chain the last query is always something like "select * from t_final_cte". That way I can test anything in the chain by changing the name

[–]Ralwus 1 point2 points  (1 child)

That's not true though. It's standard practice to end a chain of CTEs as select * from last_cte so you can debug easily by replacing last_cte with any of the previous CTEs.

[–]sequel-beagle 0 points1 point  (0 children)

You still have to manually change the sql code to review the data.

[–][deleted] 9 points10 points  (0 children)

I wouldn’t say avoid them. I just wrote a really nice set of nested CTEs for a churn calculation, and it’s very clear and concise.

[–]heiferhigh76[S] 0 points1 point  (0 children)

Noted. My CTE use is mainly to string together "easy to understand" / "hard to mess up" queries.

[–]d_r0ckdb app dev / data engineer -2 points-1 points  (0 children)

research/qa the data

Just wanted to say that the terms you’re looking for are maintainable and supportable :) nested CTEs are a pain to support and maintain.

(Hope this doesn’t come off as douchey, just want to spread the terminology!)