aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/exchange_do_insert_aml_decision.sql
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-11-17 08:53:04 +0100
committerChristian Grothoff <christian@grothoff.org>2023-11-17 08:53:04 +0100
commitfcd3493558dafd0bd667c3918e4a4d583bdc2e08 (patch)
treefd4027de91e9b56277269e7022eaa4657829c893 /src/exchangedb/exchange_do_insert_aml_decision.sql
parent8956edbef483dace07800bca4885954f01134032 (diff)
downloadexchange-fcd3493558dafd0bd667c3918e4a4d583bdc2e08.tar.xz
-on conflict update
Diffstat (limited to 'src/exchangedb/exchange_do_insert_aml_decision.sql')
-rw-r--r--src/exchangedb/exchange_do_insert_aml_decision.sql16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/exchangedb/exchange_do_insert_aml_decision.sql b/src/exchangedb/exchange_do_insert_aml_decision.sql
index 1598a4073..f46a73d07 100644
--- a/src/exchangedb/exchange_do_insert_aml_decision.sql
+++ b/src/exchangedb/exchange_do_insert_aml_decision.sql
@@ -32,7 +32,7 @@ AS $$
BEGIN
-- Check officer is eligible to make decisions.
PERFORM
- FROM exchange.aml_staff
+ FROM aml_staff
WHERE decider_pub=in_decider_pub
AND is_active
AND NOT read_only;
@@ -47,7 +47,7 @@ out_invalid_officer=FALSE;
-- Check no more recent decision exists.
SELECT decision_time
INTO out_last_date
- FROM exchange.aml_history
+ FROM aml_history
WHERE h_payto=in_h_payto
ORDER BY decision_time DESC;
IF FOUND
@@ -57,7 +57,7 @@ THEN
-- Refuse to insert older decision.
RETURN;
END IF;
- UPDATE exchange.aml_status
+ UPDATE aml_status
SET threshold=in_new_threshold
,status=in_new_status
,kyc_requirement=in_requirement_row
@@ -65,7 +65,7 @@ THEN
ASSERT FOUND, 'cannot have AML decision history but no AML status';
ELSE
out_last_date = 0;
- INSERT INTO exchange.aml_status
+ INSERT INTO aml_status
(h_payto
,threshold
,status
@@ -74,11 +74,15 @@ ELSE
(in_h_payto
,in_new_threshold
,in_new_status
- ,in_requirement_row);
+ ,in_requirement_row)
+ ON CONFLICT (h_payto) DO
+ UPDATE SET
+ threshold=in_new_threshod
+ ,status=in_new_status;
END IF;
-INSERT INTO exchange.aml_history
+INSERT INTO aml_history
(h_payto
,new_threshold
,new_status