Hi all
thanks from the beginning for all your inputs
I created a function sumlast and a trigger update_actuals
I have the following tables where I insert info:
log1 - I put some time info hours
actuals - the last updated hours info is stored here, basically each machine has only one entry in table actuals
selectedmachine - from this table I select the machine I'm currently updating the info for
and one view:
time_view - that calculates the hours from figures inserted in log1.
This is the error I received when I update the log1 table. Any idea what I'm doing wrong?
the CASE WHEN conditions is creating the error. Basicly through this condition I would like to update the hours only for the idmachine that is selected
---------------------------
pgAdmin III
---------------------------
An error has occurred:
ERROR: missing FROM-clause entry for table "actuals"
LINE 1: SELECT actuals.idmachine
^
QUERY: SELECT actuals.idmachine
CONTEXT: PL/pgSQL function sumlast() line 2 at CASE
---------------------------
OK
---------------------------
thanks from the beginning for all your inputs
I created a function sumlast and a trigger update_actuals
I have the following tables where I insert info:
log1 - I put some time info hours
actuals - the last updated hours info is stored here, basically each machine has only one entry in table actuals
selectedmachine - from this table I select the machine I'm currently updating the info for
and one view:
time_view - that calculates the hours from figures inserted in log1.
Code:
-- Trigger: update_actuals_tg on log1
-- DROP TRIGGER update_actuals_tg on log1;
CREATE TRIGGER update_actuals_tg
BEFORE INSERT
ON log1
FOR EACH ROW
EXECUTE PROCEDURE sumlast();
Code:
-- Function: sumlast()
-- DROP FUNCTION sumlast();
CREATE OR REPLACE FUNCTION sumlast()
RETURNS trigger AS
$BODY$begin
CASE actuals.idmachine
WHEN selectedmachine.idmachine THEN
update actuals
set
hours = hours + (select time from time_view
where idlog = (select max(idlog) from time_view));
END CASE;
return new;
end$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION sumlast()
OWNER TO user1;
the CASE WHEN conditions is creating the error. Basicly through this condition I would like to update the hours only for the idmachine that is selected
---------------------------
pgAdmin III
---------------------------
An error has occurred:
ERROR: missing FROM-clause entry for table "actuals"
LINE 1: SELECT actuals.idmachine
^
QUERY: SELECT actuals.idmachine
CONTEXT: PL/pgSQL function sumlast() line 2 at CASE
---------------------------
OK
---------------------------