I have a trigger that in the DECLARE section I want to define a Decimal variable based on another integer variable like this:
CREATE OR REPLACE FUNCTION my_function() RETURNS TRIGGER LANGUAGE PLPGSQL AS
$$
DECLARE
amount_tick CONSTANT INTEGER := scale(amount_tick::REAL::DECIMAL) FROM general_market WHERE id = NEW.market_id;
amount_filled DECIMAL(10, amount_tick);
BEGIN
RETURN NEW;
END;
$$;
but I got this error:
invalid input syntax for type integer: "amount_tick"
LINE X: amount_filled DECIMAL(10, amount_tick);
how can I define a decimal variable with another integer variable ?