Hacker News new | ask | show | jobs
by sgarland 14 days ago
You’d probably write a helper function that automatically runs SELECT pg_current_wal_insert_lsn() after a write and returns it.

That said, I don’t see the point. If you need to read DB-generated data (like a PK, or timestamp) from a write, use RETURNING so you get it with one call, and pass that to another function if it needs it. If it’s data you wrote, you already have it. So many web apps are slow because they have a million services, and all of them are calling the DB for the same information instead of passing it to each other.

1 comments

If you can do this and that matches the use case, sure, that's certainly the best way. But your writes and reads might have other calls in between. Another case is that the read in question is a (relatively) heavy query, which one might want to intentionally offload to a read replica.