Обсуждение: problems creating functions, triggers, and rules

Поиск
Список
Период
Сортировка

problems creating functions, triggers, and rules

От
Werner Fraga
Дата:
I am having problems creating functions, triggers and rules in Postgres 6.5.3 on
Linux Mandrake 6.1. They may all be related:

1. I noticed that some examples show the LANGUAGE in the CREATE FUNCTION
command can be 'plpgsql'. However, if I try using this instead of 'sql', I get
ERROR: Unrecognized language specified in a CREATE FUNCTION ...
However, I read somewhere that triggers don't work with LANGUAGE 'sql'.

Am I missing some part of Postgres installation?


2. If I create a function successfully (with LANGUAGE 'sql', then try to
create a trigger using this function, I get

create function checkStationID (int4) returns int4 as
'select Station.StationID from Station where Station.StationID = $1;'
language 'SQL';
CREATE

create trigger ifStationExists BEFORE INSERT OR UPDATE ON Employee FOR EACH ROW EXECUTE PROCEDURE checkStationID
(stationID);
ERROR:  CreateTrigger: function checkstationid() does not exist


3. If I create an insert rule using

create rule createStationAfterEmployeeInsert as on insert to Employee where new.StationID = 8 do insert into Station
(StationID,StationName) values (new.StationID, 'RefIntegrity');
 

the WHERE clause is ignored, and the rule is applied to all INSERTs. I also
tried 'Employee' instead of 'new'.

4. Whereas if I create an update rule using

create rule createStationAfterEmployeeUpdate as on update to Employee where old.stationID=8 do insert into Station
(StationID,StationName) values (new.StationID, 'RefIntegrity');
 

the rule is never applied. I also tried 'Employee' instead of 'old'. I tried
'current' instead of old, but this is not supported. 

5. Is there anywhere I can find a list of the system tables? (that section in
Bruce's book is not ready yet...)