Current section

Files

Jump to
ex_money_sql priv SQL postgres define_negate_operator.sql
Raw

priv/SQL/postgres/define_negate_operator.sql

CREATE OR REPLACE FUNCTION money_negate(money_1 money_with_currency)
RETURNS money_with_currency
IMMUTABLE
STRICT
LANGUAGE plpgsql
AS $$
DECLARE
currency varchar;
addition numeric;
BEGIN
currency := currency_code(money_1);
addition := amount(money_1) * -1;
return row(currency, addition);
END;
$$;
CREATE OPERATOR - (
rightarg = money_with_currency,
procedure = money_neg
);