From 29e5cd0ef5e53cfdb39f4dd5b43902c2b63571e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Fri, 14 Oct 2022 20:09:39 +0200 Subject: [PATCH] fix errors --- src/exchangedb/procedures.sql | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/exchangedb/procedures.sql b/src/exchangedb/procedures.sql index 85accfc2f..fb57b587b 100644 --- a/src/exchangedb/procedures.sql +++ b/src/exchangedb/procedures.sql @@ -2207,8 +2207,8 @@ CREATE OR REPLACE FUNCTION insert_or_update_policy_details( LANGUAGE plpgsql AS $$ DECLARE - cur_commiment_val INT8; - cur_commiment_frac INT4; + cur_commitment_val INT8; + cur_commitment_frac INT4; cur_accumulated_total_val INT8; cur_accumulated_total_frac INT4; BEGIN @@ -2238,33 +2238,29 @@ BEGIN in_transferable_val, in_transferable_frac, in_fulfillment_state) - RETURNING (policy_details_serial_id, - accumulated_total_val, - accumulated_total_frac, - fulfillment_state) - INTO (out_policy_details_serial_id, - out_accumulated_total_val, - out_accumulated_total_frac, - out_fulfillment_state) - ON CONFLICT (policy_hash_code) DO NOTHING; + ON CONFLICT (policy_hash_code) DO NOTHING + RETURNING policy_details_serial_id INTO out_policy_details_serial_id; -- If the insert was successful, return -- We assume that the fullfilment_state was correct in first place. IF FOUND THEN + out_accumulated_total_val = in_accumulated_total_val; + out_accumulated_total_frac = in_accumulated_total_frac; + out_fulfillment_state = in_fulfillment_state; RETURN; END IF; -- We had a conflict, grab the parts we need to update. - SELECT (policy_details_serial_id, + SELECT policy_details_serial_id, commitment_val, commitment_frac, accumulated_total_val, - accumulated_total_frac) - INTO (out_policy_details_serial_id, + accumulated_total_frac + INTO out_policy_details_serial_id, cur_commitment_val, cur_commitment_frac, cur_accumulated_total_val, - cur_accumulated_total_frac) + cur_accumulated_total_frac FROM policy_details WHERE policy_hash_code = in_policy_hash_code; @@ -2277,7 +2273,7 @@ BEGIN IF (out_accumulated_total_val > (1 << 52)) THEN - RAISE EXCEPTION "accumulation overflow"; + RAISE EXCEPTION 'accumulation overflow'; END IF;