Last active
September 27, 2023 00:07
-
-
Save beatak/f678538da4cbb5e089315c82be6e3ecc to your computer and use it in GitHub Desktop.
Convert PostgreSQL's WAL_LSN to bytes (int, possibly 64-bit width?)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Logic is from: | |
* https://stackoverflow.com/questions/66797767/lsn-external-representation | |
* You may also look at: | |
* https://www.crunchydata.com/blog/postgres-wal-files-and-sequuence-numbers | |
*/ | |
function lsn2int (str) { | |
return parseInt( | |
str.split('/').map((n) => n.padStart(8, '0')).join(''), | |
16 | |
); | |
}; | |
console.log(lsn2int('16/374D848')); | |
// => 94547269704 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment