Skip to content

Instantly share code, notes, and snippets.

@Ragmaanir
Created June 16, 2017 21:11
Show Gist options
  • Save Ragmaanir/c649cfbbd1fe4918fd5f18dc934bf6c8 to your computer and use it in GitHub Desktop.
Save Ragmaanir/c649cfbbd1fe4918fd5f18dc934bf6c8 to your computer and use it in GitHub Desktop.
SELECT
IF user_id IS NULL THEN
INSERT INTO scores(issue_id, user_id, group_id, value, created_at, updated_at)
VALUES($1, NULL, $3, $4, $5, $6)
ON CONFLICT(issue_id, group_id) DO UPDATE
SET value = $4, updated_at = $6
ELSE
INSERT INTO scores(issue_id, user_id, group_id, value, created_at, updated_at)
VALUES($1, $2, NULL, $4, $5, $6)
ON CONFLICT(issue_id, user_id) DO UPDATE
SET value = $4, updated_at = $6
END IF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment