Let Postgres Do the Work (2013)
Cool demonstration of IMMUTABLE functions (TIL), but there&#x27;s a reason people have moved away from stored procedures&#x2F;functions in RDBMSs in favor of moving this stuff into much slower application code -- you now have business logic living inside of the database. From there, you have to now think about how this affects:<p>- Testing<p>- Deployment&#x2F;Migrations<p>- Day-to-day tooling to work on it<p>- Switching costs (mental overhead, using multiple languages)<p>- Documentation<p>- Probably more stuff<p>The ruby code is just like all of your other ruby code and can be grokked and worked on by anyone who is up to speed on your ruby stack. The DB function meanwhile requires jumping through lots of hoops and will always feel like a second class citizen relative to the vast majority of your application code, unless you do a lot of work and maintenance (unlikely to happen without feeling distracting if this code is a relatively small slice of your code base.)<p>In some cases, this can be worth it for massive optimization wins. But the article doesn&#x27;t really touch on why this might be a bad idea.<p>I do think it highlights the potential of systems like MADLIB [1] where you can push the data crunching into the database, while having that be abstracted away in your primary programming language (in this case, R.) One could imagine a world where you wrote the ruby code and it was somehow mapped in to be run on the database. But that&#x27;s not the world we live in today unfortunately. It&#x27;s really a shame, because people using a database as capable of PostgreSQL but with a fairly dumb ORM on top are under-utilizing its potential, for sure, but there&#x27;s not really a great path afaik to leverage it. (I remember years ago MS introduced running C# inside of SQL Server, I am not sure if that ever ended up panning out into being something smarter than the dumb &quot;upload code to database manually&quot; model we are used it.)<p>[1] <a href="http:&#x2F;&#x2F;madlib.incubator.apache.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;madlib.incubator.apache.org&#x2F;</a>