Created
June 18, 2015 08:11
-
-
Save crmaxx/b4916e04d57b3bb194a8 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
DO $$ | |
DECLARE lastid bigint; | |
BEGIN | |
LOCK TABLE netscanner_host_statistics IN SHARE ROW EXCLUSIVE MODE; | |
SELECT id INTO lastid FROM netscanner_host_statistics WHERE name = 'ya.ru' AND workspace_id = 1; | |
IF NOT FOUND THEN | |
INSERT INTO netscanner_host_statistics (name, workspace_id, count_of_hosts, created_at, updated_at) VALUES ('ya.ru', 1, 1, now(), now()) RETURNING id INTO lastid; | |
ELSE | |
UPDATE netscanner_host_statistics SET count_of_hosts = count_of_hosts + 1, updated_at = now() WHERE id = lastid; | |
END IF; | |
INSERT INTO netscanner_hosts_host_statistics (host_id, host_statistic_id) VALUES (398, lastid); | |
END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment