I have a Postgres VIEW that uses a plpgsql function four times to produce an Aged Debt Report. If the row has a date in the current period the value in that row goes in col 1, if the date is last month then the value is in col 2 ... and so forth.
I call the function with a parameter and that parameter tells the function to calculate this month debt, last month debt, debt 2 months back - or in the final column everything before then.
CREATE OR REPLACE FUNCTION agedebt4(beforem integer, d_details) RETURNS double precision AS $BODY$ /* This Func creates a column for Aged Debt Reporting from d_details table The beforem parameter can be entered as 0,1,2 or 3 0 shows current period debt, 1 previous period, 2 cur period -2 and 3 shows current period less three AND EARLIER. */ DECLARE curdt date =(CURRENT_DATE); curdy text = substring(curdt,1,4); curdm text = substring(curdt,6,2); curdmi int = curdm::int; curdyi int = curdy::int; -- blah -- blah -- blah The VIEW has
SELECT agedebt4(0,d_details) AS "Current Debt", agedebt4(1,d_details) AS "CurrPeriod -1 Debt", agedebt4(2,d_details) AS "CurrPeriod -2 Debt", -- etc But I wish to have the column titles changed inside the Function. So I could actually have Oct2013 Debt Sep2013 Debt Aug2013 Debt July2013+ Earlier ... (obviously month names depending on the month of execution) ... show on the output. I don't want to change the Function name from agedebt4 - that's fine. I want the Function to amend the displayed column title.
Can this be done?