TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

SQL Pivot: Converting Rows to Columns

77 pointsby dmatrixover 6 years ago

6 comments

dansoover 6 years ago
I vaguely understand (on a theoretical level) why the syntax for pivoting in databases is necessarily convoluted, but it does underscore to me how spreadsheets have a great advantage for everyday data-exploring, at least when it comes to ease of pivoting.<p>(by &quot;everyday&quot;, I mean working with datasets small enough to fit within a spreadsheet&#x27;s limits, and aren&#x27;t yet important enough to need the reliability&#x2F;regularity that comes with importing it to a database)
评论 #18356533 未加载
karkisuniover 6 years ago
I wish there was something like this in postgres. tablefunc is a lot more complicated than this syntax.
评论 #18357081 未加载
评论 #18356566 未加载
评论 #18362794 未加载
nevi-meover 6 years ago
I had a quick look at some online material on implementations of pivot, as well as what I consider my go-to reference [0] for Apache projects&#x27; SQL support (Apache Calcite).<p>Looks like each DB has a proprietary way of pivoting, and I couldn&#x27;t find anything on pivot in Calcite. Does anyone know if the SQL impl of pivot was created specifically for Spark, or whether it&#x27;d be upstreamed to Calcite? The benefit would be that other projects that rely on Calcite for SQL support would also have pivot capabilities. I&#x27;m thinking of Apache Beam.<p>- [0] <a href="https:&#x2F;&#x2F;calcite.apache.org&#x2F;docs&#x2F;reference.html" rel="nofollow">https:&#x2F;&#x2F;calcite.apache.org&#x2F;docs&#x2F;reference.html</a>
评论 #18355984 未加载
评论 #18356201 未加载
IshKebabover 6 years ago
This is very nice. I&#x27;ve currently had to resort to MariaDB&#x27;s dynamic columns for my purposes (much nicer than a traditional entity-attribute-value solution) but this looks even nicer. Is this a Spark-only thing?
51Cardsover 6 years ago
mySQL needs this as well. We do a lot of pivot style reports for clients and while we have it down to a bit of a science now the resulting SQL is a debugging mess and not terribly efficient. (though it still runs fairly quick)
评论 #18357122 未加载
gildasover 6 years ago
Off topic: the GPDR banner on this site is a good example of dark pattern. Scrolling into a webpage does not mean I consent collecting personal info about me.
评论 #18356220 未加载
评论 #18361825 未加载
评论 #18356995 未加载
评论 #18359038 未加载