1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
-- Inserts or updates a row in the 'ranking' table.
CREATE OR REPLACE FUNCTION merge_ranking(
context1Id_ BIGINT, context2Id_ BIGINT, benchmarkId_ BIGINT,
metricId_ BIGINT, lastChangeTimestamp_ INTEGER, statId_ BIGINT,
value_ REAL, pos_ BIGINT) RETURNS VOID AS
$$
BEGIN
BEGIN
INSERT INTO ranking(
context1Id, context2Id, benchmarkId, metricId, lastChangeTimestamp,
statId, value, pos)
VALUES (
context1Id_, context2Id_, benchmarkId_, metricId_,
lastChangeTimestamp_, statId_, value_, pos_);
RETURN;
EXCEPTION WHEN unique_violation THEN
UPDATE ranking
SET context1Id = context1Id_,
lastChangeTimestamp = lastChangeTimestamp_, value = value_,
pos = pos_
WHERE context2Id = context2Id_
AND benchmarkId = benchmarkId_
AND metricId = metricId_
AND statId = statId_;
END;
END;
$$
LANGUAGE plpgsql;
|