Skip to content

Commit 17e1b37

Browse files
committed
Removed references to the steward updates. Functions should work now.
1 parent 4bd0ead commit 17e1b37

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

function/ts/updatelakeparam.sql

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,36 @@ CREATE OR REPLACE FUNCTION ts.updatelakeparam(_siteid integer,
55
RETURNS void
66
LANGUAGE plpgsql
77
AS $function$
8-
DECLARE
8+
DECLARE
99

10-
_lakeparameterid int := (SELECT lp.lakeparameterid FROM ndb.lakeparametertypes AS lp WHERE lp.lakeparameter = _lakeparameter);
11-
_nparam int := (SELECT COUNT(*) AS count FROM ndb.lakeparameters AS lp WHERE lp.siteid = _siteid GROUP BY lp.lakeparameterid HAVING lp.lakeparameterid = lakeparameterid);
12-
/* If nparam is not null, then the LakeParameter is already in Neotoma */
10+
_lakeparameterid int := (
11+
SELECT lp.lakeparameterid
12+
FROM ndb.lakeparametertypes AS lp
13+
WHERE lp.lakeparameter = _lakeparameter);
14+
_nparam int := (
15+
SELECT COUNT(*) AS count
16+
FROM ndb.lakeparameters AS lp
17+
WHERE lp.siteid = _siteid
18+
GROUP BY lp.lakeparameterid
19+
HAVING lp.lakeparameterid = lakeparameterid);
1320

14-
BEGIN
21+
/* If nparam is not null, then the LakeParameter is already in Neotoma */
1522

16-
IF _value IS NOT NULL THEN
17-
IF _nparam IS NOT NULL THEN /* parameter in Neotoma, need to change */
18-
UPDATE ndb.lakeparameters AS lp
19-
SET value = value WHERE (siteid = _siteid) AND (lp.lakeparameterid = _lakeparameterid);
20-
INSERT INTO ti.stewardupdates(contactid, tablename, pk1, pk2, operation, columnname)
21-
VALUES (_stewardcontactid, 'lakeparameters',_siteid, _lakeparameterid, 'update', 'value');
22-
ELSE
23-
INSERT INTO ndb.lakeparameters (siteid, lakeparameterid, value)
24-
VALUES (_siteid, _lakeparameterid, _value);
25-
INSERT INTO ti.stewardupdates(contactid, tablename, pk1, pk2, operation)
26-
VALUES (_stewardcontactid, 'lakeparameters', _siteid, _lakeparameterid, 'insert');
27-
END IF;
28-
ELSE
29-
IF _nparam IS NOT NULL THEN /* parameter in Neotoma, need to delete */
30-
DELETE FROM ndb.lakeparameters AS lp
31-
WHERE (lp.siteid = _siteid) AND (lp.lakeparameterid = _lakeparameterid);
32-
INSERT INTO ti.stewardupdates(contactid, tablename, pk1, pk2, operation)
33-
VALUES (_stewardcontactid, 'lakeparameters', _siteid, _lakeparameterid, 'delete');
34-
END IF;
35-
END IF;
36-
END;
23+
BEGIN
24+
IF _value IS NOT NULL THEN
25+
IF _nparam IS NOT NULL THEN /* parameter in Neotoma, need to change */
26+
UPDATE ndb.lakeparameters AS lp
27+
SET value = _value WHERE (siteid = _siteid) AND (lp.lakeparameterid = _lakeparameterid);
28+
ELSE
29+
INSERT INTO ndb.lakeparameters (siteid, lakeparameterid, value)
30+
VALUES (_siteid, _lakeparameterid, _value);
31+
END IF;
32+
ELSE
33+
IF _nparam IS NOT NULL THEN /* parameter in Neotoma, need to delete */
34+
DELETE FROM ndb.lakeparameters AS lp
35+
WHERE (lp.siteid = _siteid) AND (lp.lakeparameterid = _lakeparameterid);
36+
END IF;
37+
END IF;
38+
END;
3739

3840
$function$
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
CREATE OR REPLACE FUNCTION ts.updatesitegeopolinsert(_siteid integer, _stewardcontactid integer, _geopoliticalid integer)
22
RETURNS void
3-
LANGUAGE plpgsql
3+
LANGUAGE sql
44
AS $function$
55
BEGIN
6-
BEGIN
76
INSERT INTO ndb.sitegeopolitical(siteid, geopoliticalid)
87
VALUES (_siteid, _geopoliticalid);
9-
END;
10-
11-
DECLARE
12-
_newsitegeopoliticalid int := (SELECT sitegeopoliticalid FROM ndb.sitegeopolitical WHERE (siteid = _siteid AND geopoliticalid = _geopoliticalid));
13-
14-
BEGIN
15-
INSERT INTO ti.stewardupdates(contactid, tablename, pk1, operation)
16-
VALUES (_stewardcontactid, 'sitegeopolitical', _newsitegeopoliticalid, 'insert');
17-
END;
188
END;
199

2010
$function$

0 commit comments

Comments
 (0)