Live data from Hacker News

Advent of Code 2024 in pure SQL

databasearchitects.blogspot.com

101–110 of 110 posts

Re: Advent of Code 2024 in pure SQL

#102
I recommend Frank McSherry's real-time log of working through AoC 2023 using a SQL dialect:: https://github.com/frankmcsherry/blog/blob/master/posts/2024...

The most powerful primitive that the dialect has is (mutual) recursion, which is effectively a mechanism for outputting a fixed-point of a query.

Re: Advent of Code 2024 in pure SQL

#103
post #17
post #5

Earlier quoted context omitted.

I work a lot with databases and I've seen... stuff. It's not as bad as you might think if you know what you are doing. Most RDBMSs support recursive CTEs, it feels like writing Prolog with a slightly sadistic syntax. For something like AoC the most difficult part is probably parsing the input.

Speaking of parsing, back around y2k we were building an app that used XML everywhere, which was the style at the time, and our DBA wanted to write an xml parser in SQL (the api would involve sending XML to the database). That got vetoed. IMO, this kind of thing is what AoC is good for - you get to play with weird/obscure stuff without affecting your day job code.

Just around the same time I was working at a place that used Oracle's web app extension, with CGI endpoints written completely in PL/SQL. I did end up writing an XML parser/serializer for it.

Re: Advent of Code 2024 in pure SQL

#104
The problem with simple silver bullet solutions is that the best ones can handle maybe 80% of reasonable requirements... But it's absolutely impossible to solve any problem which happens to fall in the remaining 20% of problems. This fact is as true as ever and yet marketing of silver bullets is at an all-time high.

I teach an introductory coding course and I was surprised when one student asked me to give them some reasons why learning to code is useful instead of just using a platform like Wix. A similar question came up again (concerning a different website-building platform) in a different discussion with a family member.

I was kind of shocked that the distinction between a website and a data-driven application seems to have faded out of many people's consciousness. I'm guessing that you can probably add dynamic widgets to Wix and other similar platforms which make it seem like you can build complete apps but they can rarely get you all the way to your goal for a long-term project... And when you hit that wall, you almost need to learn the entire field of computer science from scratch just to get that last 10% of requirements implemented. You go from not having to know anything at all so literally understanding everything about computer science just to get the last 10%; or hire someone (and hope that they have the skills you need).

Re: Advent of Code 2024 in pure SQL

#105
post #97

Nicely done. I know this seems crazy at first but in my opinion big SQLs are one of the best ways to store complexity. The problem being complex is the issue. SQL is a standard, condensed, extremely performant, actually testable, and logical language. Sure, not anybody can instantly maintain it but that would be the same as if it was a lot of lines and functions in Java. The more lines the more risk for bugs. I also…

Once upon a time, as an intern, I had the 'fun' task of optimizing the performance of a stored procedure written by someone with a math phd. It was more than 6 pages when printed, and took more than 30 minutes to run (it was used in billing), and had no tests. Ended up rewriting it in native code, and it run in less than a second. Most of the work was proving it produced same results... and writing and documenting te…

I wrote a 120 line sql procedure that replaced a 8k line java royalty payment processor.

Re: Advent of Code 2024 in pure SQL

#106
post #76

I have been writing a ton of SQL -- implementing a lot of the business logic of a (stream processing) application in it. I really really like it, especially that I bring the computation to the data instead of the data to the computation. I often talk to developers who hate that idea though. They want me to instead move all the data to the backend, for a massive IO hit, just so that the computations can be expressed i…

PRQL is awesome. There's a similar competitor whose name I can't find now.

Re: Advent of Code 2024 in pure SQL

#107
post #97

Nicely done. I know this seems crazy at first but in my opinion big SQLs are one of the best ways to store complexity. The problem being complex is the issue. SQL is a standard, condensed, extremely performant, actually testable, and logical language. Sure, not anybody can instantly maintain it but that would be the same as if it was a lot of lines and functions in Java. The more lines the more risk for bugs. I also…

Once upon a time, as an intern, I had the 'fun' task of optimizing the performance of a stored procedure written by someone with a math phd. It was more than 6 pages when printed, and took more than 30 minutes to run (it was used in billing), and had no tests. Ended up rewriting it in native code, and it run in less than a second. Most of the work was proving it produced same results... and writing and documenting te…

I definitely see how this happens. SQL is easy to start with but sup hard to master. And it requires good data models.

But if both are fine there is no way that any native code will be faster than a database. No network latency, set operations, index usage, etc. DBs have all the the info to make data access fast.

Re: Advent of Code 2024 in pure SQL

#108
post #85

Earlier quoted context omitted.

Please elaborate.

CTEs can indeed align mismatched and denormalised storage to some E/R which follows some business logic. That much you can say. But CTEs allow for recursion and save time when you need complexity but you want to follow a precise step-by-step reasoning. This dis not arise as a need to solve business mess, but as a need to skip DDL for views/mviews. You can have arbitrary dimensions sliced in CTEs which does not immedi…

That makes sense. I misunderstood your OP.

Re: Advent of Code 2024 in pure SQL

#109
post #85

Earlier quoted context omitted.

CTEs can indeed align mismatched and denormalised storage to some E/R which follows some business logic. That much you can say. But CTEs allow for recursion and save time when you need complexity but you want to follow a precise step-by-step reasoning. This dis not arise as a need to solve business mess, but as a need to skip DDL for views/mviews. You can have arbitrary dimensions sliced in CTEs which does not immedi…

That makes sense. I misunderstood your OP.

I am happy you understood! I still feel this discussion is above my head, so if you are still there i would love an explanation!

Re: Advent of Code 2024 in pure SQL

#110
post #4

I reacted to this title the way I react a new menu item at Taco Bell: a strange mixture of desire, shame, and admiration for human ingenuity.

What I can't stand about Taco Bell is the fake nacho cheese. The ordinary grated cheese that is on (say) a hard taco is OK even if it's not the best, but it takes me a strong act of suppression to choke down anything with Velveeta in it. Maybe their tablet interface can be drilled into to get ingredients but as it is it's a game of chance. (Funny there is a taco stands that has the best street tacos I've seen anywhere except LA a block from Taco bell but too often it's not open when I'm there)

Seriously though,

https://www.amazon.com/Joe-Celkos-SQL-Smarties-Programming-d...

is a masterclass in extreme SQLmanship.

Post reply on HN