B
B
BranchInCode2019-12-18 23:13:51
PostgreSQL
BranchInCode, 2019-12-18 23:13:51

Why doesn't it add up the column value?

Table:

CREATE TABLE big_bank(
    id SERIAL NOT NULL PRIMARY KEY,
    fio TEXT NOT NULL,
    percent NUMERIC DEFAULT 0,
    score MONEY DEFAULT 0,
    total MONEY DEFAULT 0);

Trigger:
CREATE OR REPLACE FUNCTION autocountfunc() RETURNS TRIGGER AS $big_bank$
   BEGIN
      NEW.total = NEW.score + (NEW.percent/100 * NEW.score);
      RETURN NEW;
   END;
$big_bank$ LANGUAGE plpgsql;

CREATE TRIGGER auto_count BEFORE INSERT OR UPDATE ON big_bank FOR EACH ROW EXECUTE PROCEDURE autocuontfunc();

I put the data in a table:
INSERT INTO big_bank (fio, percent, score) VALUES ('Vittorio Scaletta A' , 2.0, 60000);

And the value should be total = 61200$, but it calculates total = 1200$, why? can't figure it out...
psql v.9.3.13

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2019-12-19
@Vetka_in_code

CREATE OR REPLACE FUNCTION autocountfunc()
EXECUTE PROCEDURE autocuontfunc()

You are using the wrong function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question