diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2023-03-12 16:45:59 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2023-03-12 23:38:12 +0900 |
commit | 40c84f86e9d7326bb0020c9210e0689179b1102c (patch) | |
tree | 6c884c18704fa726f1784fd6884048897b16d743 /deploy/insert_item.sql | |
parent | 1a838c115140bdf0f35054351153fb21f2a228da (diff) |
Add function to add new item.
Diffstat (limited to 'deploy/insert_item.sql')
-rw-r--r-- | deploy/insert_item.sql | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/deploy/insert_item.sql b/deploy/insert_item.sql new file mode 100644 index 0000000..9f4e050 --- /dev/null +++ b/deploy/insert_item.sql @@ -0,0 +1,25 @@ +-- Deploy kakeibo:insert_item to pg +-- requires: schema +-- requires: items + +BEGIN; + +CREATE OR REPLACE FUNCTION kakeibo.insert_item( + p_transaction_id INTEGER, + p_category TEXT, + p_subcategory TEXT, + p_amount INTEGER, + p_note TEXT +) RETURNS INTEGER AS $$ + DECLARE + inserted_id INTEGER; + BEGIN + INSERT INTO kakeibo.items (transaction_id, category, subcategory, amount, note) + VALUES (p_transaction_id, p_category, p_subcategory, p_amount, p_note) + RETURNING id INTO inserted_id; + + RETURN inserted_id; + END; +$$ LANGUAGE plpgsql SECURITY DEFINER; + +COMMIT; |