I was wondering if I could get some help with declaring mathematical expressions as variables in pl/pg sql.
When creating a function the general format is :
CREATE OR REPLACE FUNCTION [insert function name, input parameters and data type]
RETURNS NUMERIC
LANGUAGE plpgsql
AS
$$
DECLARE
mathEX NUMERIC; — example variable
BEGIN
—-mathematical operation—-
RETURN math_example;
END;
$$;
My question is if the purpose of my function is to create a mathematical operation but the declared variables are sub mathematical expressions to help build the primary math expression then should I store the “sub math expressions” with the variable under the “DECLARE”section? Or should they be listed first in the “BEGIN” section?
For example,
Should it be
DECLARE
X NUMERIC(8,6) : = Z/36;
Or....
DECLARE
X NUMERIC(8,6);
BEGIN
X := Z/36;
—- then insert primary math formula—-