Hacker News new | ask | show | jobs
by jsdwarf 1060 days ago
Use cases? Examples?
3 comments

Off the top of my head:

The ability to do advanced regexp replacements with a function parameter in JS far outstrips anything native in Postgres.

Array manipulation, reordering, and deduplication are worlds easier in JS than native Postgres.

Manipulating byte buffers in JS are much faster and more flexible than introspecting bytea columns in native Postgres.

JSON parsing and object transformation are much easier, faster, and clearer than native Postgres (even with the recent jsonb improvements).

my favorite (plv8, but relevant) was working at an esri r&d center, and having corporate remind us that we needed to include esri's json format in our product offering in addition to geojson (our supported format).

I was away at a conference (jsconf, amusingly), and simply added the arcgis to geojson converter that was already written in javascript as part of another open source project we had released, and voila, we could suddenly support it in the database. one of the product engineers quickly added an additional database call to the backend, and we were all set.

simple problems, simple solutions, especially when dealing with json conversion.

(I haven't tried pljs but I think this is relevant) I've used JavaScript UDFs in Snowflake for array processing and also dumb POCs things like importing an entire library for useragent parsing
Similar, we use JS UDFs in BigQuery for JSON parsing (ELT instead of ETL) and occasionally for other tasks that are just easier in JS than pure SQL.