-
-
Save jberger/5fe567677c9784c1b75a02a4578781f6 to your computer and use it in GitHub Desktop.
Conditional insert if the previous json data was different
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
return !!$self->query(<<' SQL', $id, {json => $data})->rows; | |
INSERT INTO server_data (server_id, data) | |
SELECT $1, $2 | |
WHERE COALESCE(( | |
SELECT data <> $2 | |
FROM server_data | |
WHERE server_id=$1 | |
ORDER BY ts DESC | |
LIMIT 1 | |
), 't') | |
SQL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment