aboutsummaryrefslogtreecommitdiff
path: root/deploy/insert_transaction.sql
blob: 42e825df0a5d700fb855832ee5c7caa6e465b534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- Deploy kakeibo:insert_transaction to pg
-- requires: appschema
-- requires: transactions

BEGIN;

DROP FUNCTION kakeibo.insert_transaction(kakeibo.transaction_type, DATE, TEXT);
CREATE OR REPLACE FUNCTION kakeibo.insert_transaction(
  p_type INTEGER,
  p_date DATE,
  p_note TEXT
) RETURNS INTEGER AS $$
DECLARE
  inserted_id INTEGER;
BEGIN
  INSERT INTO kakeibo.transactions (
    type, date, note
  ) VALUES (
    p_type, p_date, p_note
  ) RETURNING id INTO inserted_id;
  RETURN inserted_id;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

COMMIT;