我有以下代码,这是我想要应用触发器的表上触发器的缩小版函数,该表实际上有很多字段:
Create OR REPLACE FUNCTION PRC_EPV_()
RETURNS trigger AS $PRC_EPV_$
begin
Declare BaseCount bigint default 0;
Declare PeakCount bigint default 0;
Declare BaseSUM DOUBLE PRECISION default 0;
Declare PeakSum DOUBLE PRECISION default 0;
IF new.epv_kw_1 IS NOT NULL THEN
set BaseSum = BaseSum + new.EPV_KW_1;
set BaseCount = BaseCount + 1;
END if;
IF new.EPV_KW_38 IS NOT NULL Then
set BaseSum = BaseSum + new.EPV_KW_38;
set PeakSum = PeakSum + new.EPV_KW_38;
set BaseCount = BaseCount + 1;
set PeakCount = PeakCount + 1;
END if;
IF new.EPV_KW_91 IS NOT NULL Then
set BaseSum = BaseSum + new.EPV_KW_91;
set BaseCount = BaseCount + 1;
END if;
set new.EPV_Peak_Sum = PeakSum ;
set new.EPV_Base_Sum = BaseSum ;
IF PeakCount > 0 Then
set new.EPV_Peak_AVE = new.EPV_peak_Sum / PeakCount * 4;
END if;
IF BaseCount > 0 Then
set new.EPV_Base_AVE = new.EPV_base_Sum / BaseCount * 4;
END if;
RETURN NEW;
END;
$PRC_EPV_$ LANGUAGE plpgsql;
pgAdmin SQL编辑告诉我 错误:“IF”处或附近的语法错误 第11行:如果new.epv_kw_1是非空的那么
对于我的生活我无法解决为什么我尝试用'true','1','-1','1 = 1'替换条件语句一直在IF给我相同的语法错误
答案 0 :(得分:0)
尝试更改
RETURNS trigger AS $PRC_EPV_$
begin
Declare BaseCount bigint default 0;
Declare PeakCount bigint default 0;
Declare BaseSUM DOUBLE PRECISION default 0;
Declare PeakSum DOUBLE PRECISION default 0;
IF new.epv_kw_1
到
RETURNS trigger AS $PRC_EPV_$
Declare
BaseCount bigint default 0;
PeakCount bigint default 0;
BaseSUM DOUBLE PRECISION default 0;
PeakSum DOUBLE PRECISION default 0;
begin
IF new.epv_kw_1