我有一个 Postgres VIEW,它使用 plpgsql 函数四次来生成一个旧债务报告。如果该行在当前期间有一个日期,则该行中的值位于第 1 列,如果日期是上个月,则该值位于第 2 列……依此类推。
我用一个参数调用该函数,该参数告诉该函数计算本月债务、上个月债务、2 个月前的债务 - 或者在最后一列中计算在那之前的所有内容。
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
视图有
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
但我希望在函数内部更改列标题。所以我实际上可以有Oct2013 Debt
Sep2013 Debt
Aug2013 Debt
July2013+
Earlier
......(显然月份名称取决于执行月份)......在输出中显示。我不想从agedebt4 更改函数名称——这很好。我希望函数修改显示的列标题。
这可以做到吗?