summaryrefslogtreecommitdiffstats
path: root/database/scripts/plpgsqlfuncs.sql
blob: 052a54e7d22519e72cde7d6b1eb36b620f340656 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- 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;


-- Inserts or updates a row in the 'timeSeriesAnnotation' table.
CREATE OR REPLACE FUNCTION merge_timeSeriesNote(
    hostId_ BIGINT, platformId_ BIGINT, branchId_ BIGINT,
    benchmarkId_ BIGINT, metricId_ BIGINT, note_ TEXT) RETURNS VOID AS
$$
BEGIN
    BEGIN
        INSERT INTO timeSeriesAnnotation(
            hostId, platformId, branchId, benchmarkId, metricId, note)
        VALUES (
            hostId_, platformId_, branchId_, benchmarkId_, metricId_, note_);
        RETURN;
    EXCEPTION WHEN unique_violation THEN
        UPDATE timeSeriesAnnotation
        SET hostId = hostId_, platformId = platformId_, branchId = branchId_,
            note = note_
        WHERE hostId = hostId_
          AND platformId = platformId_
          AND branchId = branchId_
          AND benchmarkId = benchmarkId_
          AND metricId = metricId_;
    END;
END;
$$
LANGUAGE plpgsql;