Writing a function in Postgresql 8.2
I am trying to write a function in Postgres 8.2 that will analyze 4
specific columns out of a data set we use for reporting purposes and then
return text that categorizes the record with specific text.
In our old reporting environment, I would leverage the reporting tool
(Crystal Reports) to calculate this but the directive I have received is
that it should be done as a function in the database.
Here is an example of what I am trying to do (please excuse the errors, I
am still learning the basics)
CREATE FUNCTION fnc_Breakdown(character varying, character varying,
character varying, character varying)
RETURNS character varying AS $$
DECLARE
breakdown character varying;
BEGIN
IF $1 in ('ABCD') THEN breakdown:= "CSS"
ELSE
IF $1 like ('DCA%) AND $2 IN ('District 123','District 124') and $3 IN ('
THEN breakdown:= "FAB"
ELSE breakdown:= "OTHERS"
END IF;
RETURN breakdown;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
No comments:
Post a Comment