Skip to content

Instantly share code, notes, and snippets.

@DanielHons
Created August 20, 2020 21:26
Show Gist options
  • Save DanielHons/f6253064e0e7c58eaee323038601385b to your computer and use it in GitHub Desktop.
Save DanielHons/f6253064e0e7c58eaee323038601385b to your computer and use it in GitHub Desktop.
Exponential backoff with postgreSQL
/*
Given a table containing at least a column for the number of errors (with no success in between) and
frequently calling the following select will provide the candidates for a retry using an exponential backoff.
*/
SELECT * FROM retryable_error WHERE
CURRENT_TIMESTAMP > (last_retry + CAST(CONCAT(CAST(POWER(2, error_count) AS text), 's') AS INTERVAL))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment