Last active
August 29, 2015 14:23
-
-
Save crmaxx/cff2c76666c5304339cc 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
BEGIN; | |
LOCK TABLE netscanner_host_statistics IN SHARE ROW EXCLUSIVE MODE; | |
WITH upsert AS (UPDATE netscanner_host_statistics SET count_of_hosts = count_of_hosts + 1, updated_at = now() WHERE (netscanner_host_statistics.name = 'ya.ru' AND netscanner_host_statistics.workspace_id = 1) RETURNING *) INSERT INTO netscanner_host_statistics (name, workspace_id, count_of_hosts, created_at, updated_at) SELECT 'ya.ru', 1, now(), now() WHERE NOT EXISTS (SELECT * FROM upsert); | |
INSERT INTO netscanner_hosts_host_statistics (host_id, host_statistic_id) VALUES (398, ?) | |
COMMIT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment