Blocks pl pg sql

0

I am starting to use plpgsql and postgresql and the truth is that I am a bit lost, I have an exercise in which I am asked to make a block that increases the salary of the employees by 10% of the average salary of the same, and I have done this:

CREATE OR REPLACE FUNCTION increment(salari INT) RETURNS int AS $$
DECLARE
    increment int NOT NULL := salari + ((avg(salari) * 10)/100);
BEGIN
    return salari + increment;
END;
$$ LANGUAGE plpgsql;

The case is that when applying the function does not return a correct result (I know that instead of the return I have to do a update and such, but I have put it like this to go testing) , I imagine that it will be because instead of an int, I have to work with some kind of data similar to double, but it does not recognize me.

Does anyone have any idea what I could do?

    
asked by THR4SH3RP0L0 15.03.2017 в 16:47
source

1 answer

0

I just published this and I just realized that in the variable incremento was adding the salary; therefore, he was adding twice the salary.

The code would look like this:

CREATE OR REPLACE FUNCTION increment(salari INT) RETURNS int AS $$
DECLARE
    increment int NOT NULL := ((avg(salari) * 10)/100);
BEGIN
    return salari + increment;
END;
$$ LANGUAGE plpgsql;
    
answered by 15.03.2017 в 16:49