2016-11-23 208 views
1

我尝试做一个触发功能,将检查是否在插入/事件日期的记录的更新的信息是有效的:触发功能

create or replace function trigf() returns trigger as $$ 
declare bad_date record; 
begin 
    select festival.title into bad_date 
    from festival 
    where new.title = festival.title and (new.edate < festival.sdate or new.edate > festival.edate); 

    if exists bad_date then 
       raise notice 'Error: Event Date does not Correlate with the Festival.'; 
       if T = 'insert' then return null; 
        else return old; 
         end if; 
     else 
      return new; 
     end if; 
end; 
$$language plpgsql; 

create trigger T 
before insert or update on event 
for each row 
execute procedure trigf(); 

编译通过罚款,但试图插入值时,我得到bad_date不存在的错误。我想谁并欣赏热门知道任何人去修补,而不是它

回答

0

declare bad_date record; 

if exists bad_date then 

应该是:

declare bad_date text; -- or same type of festival.title 

if bad_date IS NOT NULL then