aboutsummaryrefslogtreecommitdiffstats
path: root/sql/dawn.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/dawn.sql')
-rw-r--r--sql/dawn.sql8
1 files changed, 5 insertions, 3 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index ae3fb3fe..7a8f8cb2 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -419,15 +419,17 @@ CREATE TABLE swaptions(id serial PRIMARY KEY,
CREATE TRIGGER swaptions_dealid AFTER INSERT ON swaptions
FOR EACH ROW EXECUTE PROCEDURE auto_dealid();
-CREATE OR REPLACE FUNCTION update_account()
+
+CREATE OR REPLACE FUNCTION update_account(p_trade_type)
RETURNS TRIGGER
AS $$
BEGIN
-SELECT cash_account INTO STRICT NEW.cash_account FROM accounts2 LEFT JOIN account_counterparty ON accounts2.id=account_id WHERE trade_type='ISDA' AND fund=NEW.fund AND account_counterparty.cp_code=NEW.cp_code;
+SELECT cash_account INTO STRICT NEW.cash_account FROM accounts2 LEFT JOIN account_counterparty ON accounts2.id=account_id WHERE trade_type=p_trade_type AND fund=NEW.fund AND account_counterparty.cp_code=NEW.cp_code;
RETURN NEW;
END
$$ LANGUAGE plpgsql;
+
CREATE TRIGGER cash_account BEFORE
INSERT OR UPDATE OF
fund,
@@ -435,7 +437,7 @@ INSERT OR UPDATE OF
ON
swaptions
FOR EACH ROW
-EXECUTE PROCEDURE update_account();
+EXECUTE PROCEDURE update_account('ISDA');