Live data from Hacker News

Good CTE, Bad CTE

boringsql.com

21–30 of 47 posts

Re: Good CTE, Bad CTE

#21
post #14
post #2

Use the term, never define the term, classic. CTE stands for Common Table Expressions in SQL. They are temporary result sets defined within a single query using the WITH clause, acting like named subqueries to improve readability and structure.

Agreed. I was relieved to see this wasn’t written by Cam Skatteboro.

Yeah, I thought I was on a sports site. Cam thinks CTE isn't real and is "all in your head." Technically correct about the all in your head part.

Re: Good CTE, Bad CTE

#22
To the author of the article. This was a really nice and educating read. You made me finally understand recursive CTEs, the org chart was a really good example. Thank you.

Re: Good CTE, Bad CTE

#23
post #19

There's some good stuff in here. I didn't know about the issues an aggregation in a CTE can cause and haven't used EXISTS much. Regarding recursive CTEs, you might be interested in how DuckDb evolved them with USING KEY: https://duckdb.org/2025/05/23/using-key

That was also a great read, thanks!

Re: Good CTE, Bad CTE

#24
post #3
post #2

Use the term, never define the term, classic. CTE stands for Common Table Expressions in SQL. They are temporary result sets defined within a single query using the WITH clause, acting like named subqueries to improve readability and structure.

OP here, damn - that's a very good point. Can't believe I missed it.

i appreciate the way you took the feedback. i saw the domain name and immediately knew the content and context. the article did not disappoint. i come from a heavy mssql background with some postgres sprinkled in, but my current company is migrating our mssql fleet to pg and it’s nice to have a technical foundation and article to be able to truly understand and pass the differences and similarities then how the two platforms handle workload. Traditionally it’s just been multiple sides, mercilessly criticizing each other for their deficiencies, but each platform has its own strengths and its own gaps. I’m excited to be a part of this migration, and I appreciate technical articles such as this that help me articulate the broader challenges to both our executive level levels, and our developers.

edit: syntax. voice to text was liberal with the comma abuse

Re: Good CTE, Bad CTE

#25
post #3
post #2

Use the term, never define the term, classic. CTE stands for Common Table Expressions in SQL. They are temporary result sets defined within a single query using the WITH clause, acting like named subqueries to improve readability and structure.

OP here, damn - that's a very good point. Can't believe I missed it.

I read the article before the abbreviate definition inclusion as its very opening. I had never met the abbreviation before.

It'd be quite surprising the WITH statement in top a query to be the first feature to learn/use past basic SQL. Is it personal experience in some industry?

Re: Good CTE, Bad CTE

#26
Not to sound like a broken record, but I need to echo what many other replies have already said: great article.

Embarassingly, despite thinking of myself as pretty knowledgeable with SQL, I had no idea you could nest DML statements inside a CTE. I always assumed/used DML statements as the final statement after a CTE was defined. I'm not sure if or when I might use this in the future, but it's neat to learn something new (and to be humbled at the same time).

Re: Good CTE, Bad CTE

#27
post #2

Use the term, never define the term, classic. CTE stands for Common Table Expressions in SQL. They are temporary result sets defined within a single query using the WITH clause, acting like named subqueries to improve readability and structure.

Your comment could have been more helpful without the first sentence. SAME content, same correction, less superiority: "CTE is an overloaded term, in this article ......"

This is a valuable comment, don't ruin it with sarcasm and rudeness.

Re: Good CTE, Bad CTE

#28
post #2

Use the term, never define the term, classic. CTE stands for Common Table Expressions in SQL. They are temporary result sets defined within a single query using the WITH clause, acting like named subqueries to improve readability and structure.

While generally a fair critique, the site does have "SQL" in its name.

Re: Good CTE, Bad CTE

#29
post #27
post #2

Use the term, never define the term, classic. CTE stands for Common Table Expressions in SQL. They are temporary result sets defined within a single query using the WITH clause, acting like named subqueries to improve readability and structure.

Your comment could have been more helpful without the first sentence. SAME content, same correction, less superiority: "CTE is an overloaded term, in this article ......" This is a valuable comment, don't ruin it with sarcasm and rudeness.

> Your comment could have been more helpful without the first sentence.

no it wouldn't

the whole point is to critique the post

Re: Good CTE, Bad CTE

#30

Earlier quoted context omitted.

From the headline, I thought it might be about sports-related concussions! I was morbidly curious what a "good CTE" could possibly be...

As someone who is not much of a sports person, now I was wondering what CTE means in sports. Seems to be this: > Chronic traumatic encephalopathy (CTE) is a progressive neurodegenerative disease […] > Evidence indicates that repetitive concussive and subconcussive blows to the head cause CTE. In particular, it is associated with contact sports such as boxing, American football, Australian rules football, wrestling, m…

Yep, that's it.

The NFL in the US has famously gone to great lengths to downplay the impact of CTE on current and retired players. And there have been several famous players who literally lost their minds as they aged, and we now know that was due to CTE. Something like 90% of ex-NFLers have it. The number is still really bad for collegiate players. And even high school players are at risk.

It was to the point that Will Smith starred in a movie about it. https://en.wikipedia.org/wiki/Concussion_(2015_film)

Post reply on HN