]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0720.schema.copy_loc_circ_limits.sql
LP#1564079 Checkout history skips nonexistent items
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0720.schema.copy_loc_circ_limits.sql
1 BEGIN;
2
3 SELECT evergreen.upgrade_deps_block_check('0720', :eg_version);
4
5 ALTER TABLE config.circ_matrix_weights 
6     ADD COLUMN copy_location NUMERIC(6,2) NOT NULL DEFAULT 5.0;
7 UPDATE config.circ_matrix_weights 
8     SET copy_location = 0.0 WHERE name = 'All_Equal';
9 ALTER TABLE config.circ_matrix_weights 
10     ALTER COLUMN copy_location DROP DEFAULT; -- for consistency w/ baseline schema
11
12 ALTER TABLE config.circ_matrix_matchpoint
13     ADD COLUMN copy_location INTEGER REFERENCES asset.copy_location (id) DEFERRABLE INITIALLY DEFERRED;
14
15 DROP INDEX config.ccmm_once_per_paramset;
16
17 CREATE UNIQUE INDEX ccmm_once_per_paramset ON config.circ_matrix_matchpoint (org_unit, grp, COALESCE(circ_modifier, ''), COALESCE(copy_location::TEXT, ''), COALESCE(marc_type, ''), COALESCE(marc_form, ''), COALESCE(marc_bib_level,''), COALESCE(marc_vr_format, ''), COALESCE(copy_circ_lib::TEXT, ''), COALESCE(copy_owning_lib::TEXT, ''), COALESCE(user_home_ou::TEXT, ''), COALESCE(ref_flag::TEXT, ''), COALESCE(juvenile_flag::TEXT, ''), COALESCE(is_renewal::TEXT, ''), COALESCE(usr_age_lower_bound::TEXT, ''), COALESCE(usr_age_upper_bound::TEXT, ''), COALESCE(item_age::TEXT, '')) WHERE active;
18
19 -- Linkage between limit sets and circ mods
20 CREATE TABLE config.circ_limit_set_copy_loc_map (
21     id          SERIAL  PRIMARY KEY,
22     limit_set   INT     NOT NULL REFERENCES config.circ_limit_set (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
23     copy_loc    INT     NOT NULL REFERENCES asset.copy_location (id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
24     CONSTRAINT cl_once_per_set UNIQUE (limit_set, copy_loc)
25 );
26
27 -- Add support for checking config.circ_limit_set_copy_loc_map's
28 CREATE OR REPLACE FUNCTION action.item_user_circ_test( circ_ou INT, match_item BIGINT, match_user INT, renewal BOOL ) 
29     RETURNS SETOF action.circ_matrix_test_result AS $func$
30 DECLARE
31     user_object             actor.usr%ROWTYPE;
32     standing_penalty        config.standing_penalty%ROWTYPE;
33     item_object             asset.copy%ROWTYPE;
34     item_status_object      config.copy_status%ROWTYPE;
35     item_location_object    asset.copy_location%ROWTYPE;
36     result                  action.circ_matrix_test_result;
37     circ_test               action.found_circ_matrix_matchpoint;
38     circ_matchpoint         config.circ_matrix_matchpoint%ROWTYPE;
39     circ_limit_set          config.circ_limit_set%ROWTYPE;
40     hold_ratio              action.hold_stats%ROWTYPE;
41     penalty_type            TEXT;
42     items_out               INT;
43     context_org_list        INT[];
44     done                    BOOL := FALSE;
45 BEGIN
46     -- Assume success unless we hit a failure condition
47     result.success := TRUE;
48
49     -- Need user info to look up matchpoints
50     SELECT INTO user_object * FROM actor.usr WHERE id = match_user AND NOT deleted;
51
52     -- (Insta)Fail if we couldn't find the user
53     IF user_object.id IS NULL THEN
54         result.fail_part := 'no_user';
55         result.success := FALSE;
56         done := TRUE;
57         RETURN NEXT result;
58         RETURN;
59     END IF;
60
61     -- Need item info to look up matchpoints
62     SELECT INTO item_object * FROM asset.copy WHERE id = match_item AND NOT deleted;
63
64     -- (Insta)Fail if we couldn't find the item 
65     IF item_object.id IS NULL THEN
66         result.fail_part := 'no_item';
67         result.success := FALSE;
68         done := TRUE;
69         RETURN NEXT result;
70         RETURN;
71     END IF;
72
73     SELECT INTO circ_test * FROM action.find_circ_matrix_matchpoint(circ_ou, item_object, user_object, renewal);
74
75     circ_matchpoint             := circ_test.matchpoint;
76     result.matchpoint           := circ_matchpoint.id;
77     result.circulate            := circ_matchpoint.circulate;
78     result.duration_rule        := circ_matchpoint.duration_rule;
79     result.recurring_fine_rule  := circ_matchpoint.recurring_fine_rule;
80     result.max_fine_rule        := circ_matchpoint.max_fine_rule;
81     result.hard_due_date        := circ_matchpoint.hard_due_date;
82     result.renewals             := circ_matchpoint.renewals;
83     result.grace_period         := circ_matchpoint.grace_period;
84     result.buildrows            := circ_test.buildrows;
85
86     -- (Insta)Fail if we couldn't find a matchpoint
87     IF circ_test.success = false THEN
88         result.fail_part := 'no_matchpoint';
89         result.success := FALSE;
90         done := TRUE;
91         RETURN NEXT result;
92         RETURN;
93     END IF;
94
95     -- All failures before this point are non-recoverable
96     -- Below this point are possibly overridable failures
97
98     -- Fail if the user is barred
99     IF user_object.barred IS TRUE THEN
100         result.fail_part := 'actor.usr.barred';
101         result.success := FALSE;
102         done := TRUE;
103         RETURN NEXT result;
104     END IF;
105
106     -- Fail if the item can't circulate
107     IF item_object.circulate IS FALSE THEN
108         result.fail_part := 'asset.copy.circulate';
109         result.success := FALSE;
110         done := TRUE;
111         RETURN NEXT result;
112     END IF;
113
114     -- Fail if the item isn't in a circulateable status on a non-renewal
115     IF NOT renewal AND item_object.status NOT IN ( 0, 7, 8 ) THEN 
116         result.fail_part := 'asset.copy.status';
117         result.success := FALSE;
118         done := TRUE;
119         RETURN NEXT result;
120     -- Alternately, fail if the item isn't checked out on a renewal
121     ELSIF renewal AND item_object.status <> 1 THEN
122         result.fail_part := 'asset.copy.status';
123         result.success := FALSE;
124         done := TRUE;
125         RETURN NEXT result;
126     END IF;
127
128     -- Fail if the item can't circulate because of the shelving location
129     SELECT INTO item_location_object * FROM asset.copy_location WHERE id = item_object.location;
130     IF item_location_object.circulate IS FALSE THEN
131         result.fail_part := 'asset.copy_location.circulate';
132         result.success := FALSE;
133         done := TRUE;
134         RETURN NEXT result;
135     END IF;
136
137     -- Use Circ OU for penalties and such
138     SELECT INTO context_org_list ARRAY_AGG(id) FROM actor.org_unit_full_path( circ_ou );
139
140     IF renewal THEN
141         penalty_type = '%RENEW%';
142     ELSE
143         penalty_type = '%CIRC%';
144     END IF;
145
146     FOR standing_penalty IN
147         SELECT  DISTINCT csp.*
148           FROM  actor.usr_standing_penalty usp
149                 JOIN config.standing_penalty csp ON (csp.id = usp.standing_penalty)
150           WHERE usr = match_user
151                 AND usp.org_unit IN ( SELECT * FROM unnest(context_org_list) )
152                 AND (usp.stop_date IS NULL or usp.stop_date > NOW())
153                 AND csp.block_list LIKE penalty_type LOOP
154
155         result.fail_part := standing_penalty.name;
156         result.success := FALSE;
157         done := TRUE;
158         RETURN NEXT result;
159     END LOOP;
160
161     -- Fail if the test is set to hard non-circulating
162     IF circ_matchpoint.circulate IS FALSE THEN
163         result.fail_part := 'config.circ_matrix_test.circulate';
164         result.success := FALSE;
165         done := TRUE;
166         RETURN NEXT result;
167     END IF;
168
169     -- Fail if the total copy-hold ratio is too low
170     IF circ_matchpoint.total_copy_hold_ratio IS NOT NULL THEN
171         SELECT INTO hold_ratio * FROM action.copy_related_hold_stats(match_item);
172         IF hold_ratio.total_copy_ratio IS NOT NULL AND hold_ratio.total_copy_ratio < circ_matchpoint.total_copy_hold_ratio THEN
173             result.fail_part := 'config.circ_matrix_test.total_copy_hold_ratio';
174             result.success := FALSE;
175             done := TRUE;
176             RETURN NEXT result;
177         END IF;
178     END IF;
179
180     -- Fail if the available copy-hold ratio is too low
181     IF circ_matchpoint.available_copy_hold_ratio IS NOT NULL THEN
182         IF hold_ratio.hold_count IS NULL THEN
183             SELECT INTO hold_ratio * FROM action.copy_related_hold_stats(match_item);
184         END IF;
185         IF hold_ratio.available_copy_ratio IS NOT NULL AND hold_ratio.available_copy_ratio < circ_matchpoint.available_copy_hold_ratio THEN
186             result.fail_part := 'config.circ_matrix_test.available_copy_hold_ratio';
187             result.success := FALSE;
188             done := TRUE;
189             RETURN NEXT result;
190         END IF;
191     END IF;
192
193     -- Fail if the user has too many items out by defined limit sets
194     FOR circ_limit_set IN SELECT ccls.* FROM config.circ_limit_set ccls
195       JOIN config.circ_matrix_limit_set_map ccmlsm ON ccmlsm.limit_set = ccls.id
196       WHERE ccmlsm.active AND ( ccmlsm.matchpoint = circ_matchpoint.id OR
197         ( ccmlsm.matchpoint IN (SELECT * FROM unnest(result.buildrows)) AND ccmlsm.fallthrough )
198         ) LOOP
199             IF circ_limit_set.items_out > 0 AND NOT renewal THEN
200                 SELECT INTO context_org_list ARRAY_AGG(aou.id)
201                   FROM actor.org_unit_full_path( circ_ou ) aou
202                     JOIN actor.org_unit_type aout ON aou.ou_type = aout.id
203                   WHERE aout.depth >= circ_limit_set.depth;
204                 IF circ_limit_set.global THEN
205                     WITH RECURSIVE descendant_depth AS (
206                         SELECT  ou.id,
207                             ou.parent_ou
208                         FROM  actor.org_unit ou
209                         WHERE ou.id IN (SELECT * FROM unnest(context_org_list))
210                             UNION
211                         SELECT  ou.id,
212                             ou.parent_ou
213                         FROM  actor.org_unit ou
214                             JOIN descendant_depth ot ON (ot.id = ou.parent_ou)
215                     ) SELECT INTO context_org_list ARRAY_AGG(ou.id) FROM actor.org_unit ou JOIN descendant_depth USING (id);
216                 END IF;
217                 SELECT INTO items_out COUNT(DISTINCT circ.id)
218                   FROM action.circulation circ
219                     JOIN asset.copy copy ON (copy.id = circ.target_copy)
220                     LEFT JOIN action.circulation_limit_group_map aclgm ON (circ.id = aclgm.circ)
221                   WHERE circ.usr = match_user
222                     AND circ.circ_lib IN (SELECT * FROM unnest(context_org_list))
223                     AND circ.checkin_time IS NULL
224                     AND (circ.stop_fines IN ('MAXFINES','LONGOVERDUE') OR circ.stop_fines IS NULL)
225                     AND (copy.circ_modifier IN (SELECT circ_mod FROM config.circ_limit_set_circ_mod_map WHERE limit_set = circ_limit_set.id)
226                         OR copy.location IN (SELECT copy_loc FROM config.circ_limit_set_copy_loc_map WHERE limit_set = circ_limit_set.id)
227                         OR aclgm.limit_group IN (SELECT limit_group FROM config.circ_limit_set_group_map WHERE limit_set = circ_limit_set.id)
228                     );
229                 IF items_out >= circ_limit_set.items_out THEN
230                     result.fail_part := 'config.circ_matrix_circ_mod_test';
231                     result.success := FALSE;
232                     done := TRUE;
233                     RETURN NEXT result;
234                 END IF;
235             END IF;
236             SELECT INTO result.limit_groups result.limit_groups || ARRAY_AGG(limit_group) FROM config.circ_limit_set_group_map WHERE limit_set = circ_limit_set.id AND NOT check_only;
237     END LOOP;
238
239     -- If we passed everything, return the successful matchpoint
240     IF NOT done THEN
241         RETURN NEXT result;
242     END IF;
243
244     RETURN;
245 END;
246 $func$ LANGUAGE plpgsql;
247
248
249 -- adding copy_loc to circ_matrix_matchpoint
250 CREATE OR REPLACE FUNCTION action.find_circ_matrix_matchpoint( context_ou INT, item_object asset.copy, user_object actor.usr, renewal BOOL ) RETURNS action.found_circ_matrix_matchpoint AS $func$
251 DECLARE
252     cn_object       asset.call_number%ROWTYPE;
253     rec_descriptor  metabib.rec_descriptor%ROWTYPE;
254     cur_matchpoint  config.circ_matrix_matchpoint%ROWTYPE;
255     matchpoint      config.circ_matrix_matchpoint%ROWTYPE;
256     weights         config.circ_matrix_weights%ROWTYPE;
257     user_age        INTERVAL;
258     my_item_age     INTERVAL;
259     denominator     NUMERIC(6,2);
260     row_list        INT[];
261     result          action.found_circ_matrix_matchpoint;
262 BEGIN
263     -- Assume failure
264     result.success = false;
265
266     -- Fetch useful data
267     SELECT INTO cn_object       * FROM asset.call_number        WHERE id = item_object.call_number;
268     SELECT INTO rec_descriptor  * FROM metabib.rec_descriptor   WHERE record = cn_object.record;
269
270     -- Pre-generate this so we only calc it once
271     IF user_object.dob IS NOT NULL THEN
272         SELECT INTO user_age age(user_object.dob);
273     END IF;
274
275     -- Ditto
276     SELECT INTO my_item_age age(coalesce(item_object.active_date, now()));
277
278     -- Grab the closest set circ weight setting.
279     SELECT INTO weights cw.*
280       FROM config.weight_assoc wa
281            JOIN config.circ_matrix_weights cw ON (cw.id = wa.circ_weights)
282            JOIN actor.org_unit_ancestors_distance( context_ou ) d ON (wa.org_unit = d.id)
283       WHERE active
284       ORDER BY d.distance
285       LIMIT 1;
286
287     -- No weights? Bad admin! Defaults to handle that anyway.
288     IF weights.id IS NULL THEN
289         weights.grp                 := 11.0;
290         weights.org_unit            := 10.0;
291         weights.circ_modifier       := 5.0;
292         weights.copy_location       := 5.0;
293         weights.marc_type           := 4.0;
294         weights.marc_form           := 3.0;
295         weights.marc_bib_level      := 2.0;
296         weights.marc_vr_format      := 2.0;
297         weights.copy_circ_lib       := 8.0;
298         weights.copy_owning_lib     := 8.0;
299         weights.user_home_ou        := 8.0;
300         weights.ref_flag            := 1.0;
301         weights.juvenile_flag       := 6.0;
302         weights.is_renewal          := 7.0;
303         weights.usr_age_lower_bound := 0.0;
304         weights.usr_age_upper_bound := 0.0;
305         weights.item_age            := 0.0;
306     END IF;
307
308     -- Determine the max (expected) depth (+1) of the org tree and max depth of the permisson tree
309     -- If you break your org tree with funky parenting this may be wrong
310     -- Note: This CTE is duplicated in the find_hold_matrix_matchpoint function, and it may be a good idea to split it off to a function
311     -- We use one denominator for all tree-based checks for when permission groups and org units have the same weighting
312     WITH all_distance(distance) AS (
313             SELECT depth AS distance FROM actor.org_unit_type
314         UNION
315             SELECT distance AS distance FROM permission.grp_ancestors_distance((SELECT id FROM permission.grp_tree WHERE parent IS NULL))
316         )
317     SELECT INTO denominator MAX(distance) + 1 FROM all_distance;
318
319     -- Loop over all the potential matchpoints
320     FOR cur_matchpoint IN
321         SELECT m.*
322           FROM  config.circ_matrix_matchpoint m
323                 /*LEFT*/ JOIN permission.grp_ancestors_distance( user_object.profile ) upgad ON m.grp = upgad.id
324                 /*LEFT*/ JOIN actor.org_unit_ancestors_distance( context_ou ) ctoua ON m.org_unit = ctoua.id
325                 LEFT JOIN actor.org_unit_ancestors_distance( cn_object.owning_lib ) cnoua ON m.copy_owning_lib = cnoua.id
326                 LEFT JOIN actor.org_unit_ancestors_distance( item_object.circ_lib ) iooua ON m.copy_circ_lib = iooua.id
327                 LEFT JOIN actor.org_unit_ancestors_distance( user_object.home_ou  ) uhoua ON m.user_home_ou = uhoua.id
328           WHERE m.active
329                 -- Permission Groups
330              -- AND (m.grp                      IS NULL OR upgad.id IS NOT NULL) -- Optional Permission Group?
331                 -- Org Units
332              -- AND (m.org_unit                 IS NULL OR ctoua.id IS NOT NULL) -- Optional Org Unit?
333                 AND (m.copy_owning_lib          IS NULL OR cnoua.id IS NOT NULL)
334                 AND (m.copy_circ_lib            IS NULL OR iooua.id IS NOT NULL)
335                 AND (m.user_home_ou             IS NULL OR uhoua.id IS NOT NULL)
336                 -- Circ Type
337                 AND (m.is_renewal               IS NULL OR m.is_renewal = renewal)
338                 -- Static User Checks
339                 AND (m.juvenile_flag            IS NULL OR m.juvenile_flag = user_object.juvenile)
340                 AND (m.usr_age_lower_bound      IS NULL OR (user_age IS NOT NULL AND m.usr_age_lower_bound < user_age))
341                 AND (m.usr_age_upper_bound      IS NULL OR (user_age IS NOT NULL AND m.usr_age_upper_bound > user_age))
342                 -- Static Item Checks
343                 AND (m.circ_modifier            IS NULL OR m.circ_modifier = item_object.circ_modifier)
344                 AND (m.copy_location            IS NULL OR m.copy_location = item_object.location)
345                 AND (m.marc_type                IS NULL OR m.marc_type = COALESCE(item_object.circ_as_type, rec_descriptor.item_type))
346                 AND (m.marc_form                IS NULL OR m.marc_form = rec_descriptor.item_form)
347                 AND (m.marc_bib_level           IS NULL OR m.marc_bib_level = rec_descriptor.bib_level)
348                 AND (m.marc_vr_format           IS NULL OR m.marc_vr_format = rec_descriptor.vr_format)
349                 AND (m.ref_flag                 IS NULL OR m.ref_flag = item_object.ref)
350                 AND (m.item_age                 IS NULL OR (my_item_age IS NOT NULL AND m.item_age > my_item_age))
351           ORDER BY
352                 -- Permission Groups
353                 CASE WHEN upgad.distance        IS NOT NULL THEN 2^(2*weights.grp - (upgad.distance/denominator)) ELSE 0.0 END +
354                 -- Org Units
355                 CASE WHEN ctoua.distance        IS NOT NULL THEN 2^(2*weights.org_unit - (ctoua.distance/denominator)) ELSE 0.0 END +
356                 CASE WHEN cnoua.distance        IS NOT NULL THEN 2^(2*weights.copy_owning_lib - (cnoua.distance/denominator)) ELSE 0.0 END +
357                 CASE WHEN iooua.distance        IS NOT NULL THEN 2^(2*weights.copy_circ_lib - (iooua.distance/denominator)) ELSE 0.0 END +
358                 CASE WHEN uhoua.distance        IS NOT NULL THEN 2^(2*weights.user_home_ou - (uhoua.distance/denominator)) ELSE 0.0 END +
359                 -- Circ Type                    -- Note: 4^x is equiv to 2^(2*x)
360                 CASE WHEN m.is_renewal          IS NOT NULL THEN 4^weights.is_renewal ELSE 0.0 END +
361                 -- Static User Checks
362                 CASE WHEN m.juvenile_flag       IS NOT NULL THEN 4^weights.juvenile_flag ELSE 0.0 END +
363                 CASE WHEN m.usr_age_lower_bound IS NOT NULL THEN 4^weights.usr_age_lower_bound ELSE 0.0 END +
364                 CASE WHEN m.usr_age_upper_bound IS NOT NULL THEN 4^weights.usr_age_upper_bound ELSE 0.0 END +
365                 -- Static Item Checks
366                 CASE WHEN m.circ_modifier       IS NOT NULL THEN 4^weights.circ_modifier ELSE 0.0 END +
367                 CASE WHEN m.copy_location       IS NOT NULL THEN 4^weights.copy_location ELSE 0.0 END +
368                 CASE WHEN m.marc_type           IS NOT NULL THEN 4^weights.marc_type ELSE 0.0 END +
369                 CASE WHEN m.marc_form           IS NOT NULL THEN 4^weights.marc_form ELSE 0.0 END +
370                 CASE WHEN m.marc_vr_format      IS NOT NULL THEN 4^weights.marc_vr_format ELSE 0.0 END +
371                 CASE WHEN m.ref_flag            IS NOT NULL THEN 4^weights.ref_flag ELSE 0.0 END +
372                 -- Item age has a slight adjustment to weight based on value.
373                 -- This should ensure that a shorter age limit comes first when all else is equal.
374                 -- NOTE: This assumes that intervals will normally be in days.
375                 CASE WHEN m.item_age            IS NOT NULL THEN 4^weights.item_age - 1 + 86400/EXTRACT(EPOCH FROM m.item_age) ELSE 0.0 END DESC,
376                 -- Final sort on id, so that if two rules have the same sorting in the previous sort they have a defined order
377                 -- This prevents "we changed the table order by updating a rule, and we started getting different results"
378                 m.id LOOP
379
380         -- Record the full matching row list
381         row_list := row_list || cur_matchpoint.id;
382
383         -- No matchpoint yet?
384         IF matchpoint.id IS NULL THEN
385             -- Take the entire matchpoint as a starting point
386             matchpoint := cur_matchpoint;
387             CONTINUE; -- No need to look at this row any more.
388         END IF;
389
390         -- Incomplete matchpoint?
391         IF matchpoint.circulate IS NULL THEN
392             matchpoint.circulate := cur_matchpoint.circulate;
393         END IF;
394         IF matchpoint.duration_rule IS NULL THEN
395             matchpoint.duration_rule := cur_matchpoint.duration_rule;
396         END IF;
397         IF matchpoint.recurring_fine_rule IS NULL THEN
398             matchpoint.recurring_fine_rule := cur_matchpoint.recurring_fine_rule;
399         END IF;
400         IF matchpoint.max_fine_rule IS NULL THEN
401             matchpoint.max_fine_rule := cur_matchpoint.max_fine_rule;
402         END IF;
403         IF matchpoint.hard_due_date IS NULL THEN
404             matchpoint.hard_due_date := cur_matchpoint.hard_due_date;
405         END IF;
406         IF matchpoint.total_copy_hold_ratio IS NULL THEN
407             matchpoint.total_copy_hold_ratio := cur_matchpoint.total_copy_hold_ratio;
408         END IF;
409         IF matchpoint.available_copy_hold_ratio IS NULL THEN
410             matchpoint.available_copy_hold_ratio := cur_matchpoint.available_copy_hold_ratio;
411         END IF;
412         IF matchpoint.renewals IS NULL THEN
413             matchpoint.renewals := cur_matchpoint.renewals;
414         END IF;
415         IF matchpoint.grace_period IS NULL THEN
416             matchpoint.grace_period := cur_matchpoint.grace_period;
417         END IF;
418     END LOOP;
419
420     -- Check required fields
421     IF matchpoint.circulate             IS NOT NULL AND
422        matchpoint.duration_rule         IS NOT NULL AND
423        matchpoint.recurring_fine_rule   IS NOT NULL AND
424        matchpoint.max_fine_rule         IS NOT NULL THEN
425         -- All there? We have a completed match.
426         result.success := true;
427     END IF;
428
429     -- Include the assembled matchpoint, even if it isn't complete
430     result.matchpoint := matchpoint;
431
432     -- Include (for debugging) the full list of matching rows
433     result.buildrows := row_list;
434
435     -- Hand the result back to caller
436     RETURN result;
437 END;
438 $func$ LANGUAGE plpgsql;
439
440 COMMIT;
441