Last active
August 29, 2015 14:27
-
-
Save jueyang/1c00f0767e0ab7fa5746 to your computer and use it in GitHub Desktop.
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
$insert = "INSERT INTO spider_count (spider, tally) SELECT 'Googlebot', 1"; | |
$upsert = "UPDATE spider_count SET tally=tally+1 WHERE date='today' AND spider='Googlebot'"; | |
WITH upsert AS ($upsert RETURNING *) $insert WHERE NOT EXISTS (SELECT * FROM upsert); | |
--- expanded | |
WITH upsert AS ( | |
UPDATE spider_counts | |
SET tally=tally+1 | |
WHERE date='today' AND spider='Googlebot' | |
RETURNING * | |
) | |
INSERT INTO spider_counts (spider, tally) | |
SELECT 'Googlebot', 1 | |
WHERE NOT EXISTS ( | |
SELECT * FROM upsert | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment