我对 psql 完全陌生。当我使用 http://sqlfiddle.com/ 做一些作业时,系统返回此错误。
ERROR: syntax error at or near "RETURNS"
任何帮助表示赞赏。这是我的 psql:
CREATE TABLE HotelStays
(roomNum INTEGER NOT NULL,
arrDate DATE NOT NULL,
depDate DATE NOT NULL,
guestName CHAR(30) NOT NULL,
PRIMARY KEY (roomNum, arrDate))
;
CREATE OR REPLACE FUNCTION stopInsert RETURNS trigger AS
$body$
DECLARE
availableArrDate DATE;
checkRoomNum INTEGER;
BEGIN
if (NEW.arrDate >= NEW.depDate) then
return null;
end if;
checkRoomNum = NEW.roomNum;
select h.depDate into availableArrDate
from HotelStays h
where h.roomNum = checkRoomNum
order by h.depDate DESC
LIMIT 1;
if (availableArrDate > NEW.arrDate)
return null;
end if;
END;
$body$ LANGUAGE plpgsql;
create trigger stopInsert before insert ON HotelStays
For each row
execute procedure stopInsert();