diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2023-03-12 16:23:41 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2023-03-12 23:38:12 +0900 |
commit | 1a838c115140bdf0f35054351153fb21f2a228da (patch) | |
tree | 598cae31e6b2cbeab53a84dd46a1e62ca7f0b9df /deploy | |
parent | cd23d52c0c5c3d3264c5a8706c2c6fe2b1649640 (diff) |
Add function to create new transaction.
Diffstat (limited to 'deploy')
-rw-r--r-- | deploy/insert_transaction.sql | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/deploy/insert_transaction.sql b/deploy/insert_transaction.sql new file mode 100644 index 0000000..eb5a38e --- /dev/null +++ b/deploy/insert_transaction.sql @@ -0,0 +1,24 @@ +-- Deploy kakeibo:insert_transaction to pg +-- requires: schema +-- requires: transactions + +BEGIN; + +CREATE OR REPLACE FUNCTION kakeibo.insert_transaction( + p_type_code INTEGER, + p_date DATE, + p_note TEXT +) RETURNS INTEGER AS $$ + DECLARE + inserted_id INTEGER; + BEGIN + INSERT INTO kakeibo.transactions ( + type_code, date, note + ) VALUES ( + p_type_code, p_date, p_note + ) RETURNING id INTO inserted_id; + RETURN inserted_id; + END; +$$ LANGUAGE plpgsql SECURITY DEFINER; + +COMMIT; |