你有这样的代码,IF附近有语法错误。任何人都可以睁开眼睛看我错在哪里?
CREATE OR REPLACE FUNCTION accruals_daily_posting_func()
RETURNS VARCHAR AS $$
BEGIN
DROP TABLE IF EXISTS t;
CREATE TEMPORARY TABLE t as ( SELECT sum( actual_trade_spend ) AS sum_ad FROM accruals_detailed );
IF CURRENT_DATE > ( SELECT max( posting_date ) FROM accruals_daily_posting ) THEN
BEGIN
INSERT INTO accruals_daily_posting VALUES
(
now()::date AS posting_date,
( SELECT sum_ad FROM t ) AS total_trade_spend_in_the_system,
( SELECT sum_ad - ( SELECT total_trade_spend_in_the_system FROM accruals_daily_posting
WHERE posting_date = ( SELECT max( posting_date ) FROM accruals_daily_posting )
) FROM t ) AS change_in_total_trade_spend_in_the_system_since_previous_date,
TIMESTAMP AS created_at,
TIMESTAMP AS updated_at
);
RETURN 'Successfully done';
END IF;
END;
$$ LANGUAGE plpgsql;