News for hackers. Stuff that matters.
Re:RFC6238 TOTP implementation in pure PostgreSQL by aidos on Thursday February 25, 2021 @05:42AM (#26261635)
Maybe this is the case in general, but a while back we did something that required flipping an array and when we did it with python inside Postgres it was several magnitudes faster.
Re:RFC6238 TOTP implementation in pure PostgreSQL by scrollaway on Thursday February 25, 2021 @06:14AM (#26261765)
This would make for a super interesting blog post / case study IMO, you should write about it even if it's just to showcase the two algorithms / comparisons.
Re:RFC6238 TOTP implementation in pure PostgreSQL by aidos on Friday February 26, 2021 @04:17PM (#26279945)
Sorry, but late back but I’ve just found the code.

It’s a bit of a weird case where I needed to reverse arrays inside a big json blob (millions of big json blobs). Trying to explode the structures out and rebuild them was a bit of a no-go. Instead I did a nasty little regex replace on the json string:

    re.sub('"key": \[([^\\]]+)\]', lambda match: '"key": [' + ', '.join(reversed(match.group(1).split(', '))) + "]", els)
There might be a way of doing this in postgres these days (this was 3 or 4 years ago), but I'm not sure. At the time this was the best I could come up with and I was pretty surprised it worked as well as it did.

Since then I've always installed the python extension whenever I set up a new postgres, just in case.

Re:RFC6238 TOTP implementation in pure PostgreSQL by pyramation on Monday March 01, 2021 @12:29AM (#26300012)
for sure there are all sorts of postgres regex tools... You can likely do everything. The main limitations I found in plpgsql were in base encodings (that were missing), which is why I had to implement base32 from scratch. Besides that, it's pretty much a super powerful language