SQL 함수는 trigger
을 반환 할 수 없습니다. 아마도 plpgsql 함수를 작성하려고했을 것입니다.
트리거 기능은 결과 (예 : select
쿼리의 결과)를 생성 할 수 없습니다. 당신은 클라이언트 프로그램에 어떤 결과를 전달하는 raise notice
를 사용할 수 있습니다
create or replace function added_product_info()
returns trigger as $$
declare
company text;
begin
select companyname
from suppliers
where supplierid = new.supplierid
into company;
raise notice 'inserted: "%" supplied by "%"', new.productname, company;
return new;
end;
$$ language plpgsql;
기록 new
레코드 new
및 old
에 액세스 할 수없는 경우 (기본값은 for each statement
입니다 for each row
트리거가 선언 된 경우에만 트리거 기능에서 볼 수 있습니다) : 트리거가
create trigger added_product_info_trigger
before insert on products
for each row
execute procedure added_product_info();
경우 before insert for each row
는 new
을 반환해야합니다.
클라이언트는 통지를 받고 처리 할 준비가되어 있어야합니다. 당신은 표준 psql의 쉘 프로그램에서 쿼리를 실행하면 , 당신은 얻을 것이다 :
insert into products values ('some product', 1);
NOTICE: inserted: "some product" supplied by "company"
INSERT 0 1
읽기 :
'인상 공지 ': https : // w ww.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html#PLPGSQL-STATEMENTSRAISE –