chester c young wrote:

http://www.postgresql.org/docs/8.2/interactive/plpgsql.html

I found the doc to be quite good.

I'd start there, and then, if you have problems, email again.


I'd read that before... but another re-read triggered a thought pattern and I've got it working now - it's also a lot cleaner than the SQL Server implementation:

CREATE OR REPLACE function fn_update_so_tran() RETURNS TRIGGER AS $trg_update_so_tran$
DECLARE
BEGIN
   IF (NEW.tran_status = 'U') OR (NEW.tran_status = 'D') THEN
      UPDATE parts_purchasing SET
         qty_received=qty_received + NEW.qty_received,
         qty_invoiced = qty_invoiced + NEW.qty_invoiced,
         amt_invoiced = amt_invoiced + NEW.amt_invoiced,
         amt_received = amt_received + NEW.amt_received
      WHERE dealer_id = NEW.dealer_id
         AND so_tran_address = NEW.so_tran_address
         AND this_tran_address = so_tran_address;
   END IF;
   RETURN NULL;
END;
$trg_update_so_tran$ LANGUAGE plpgsql;
ALTER FUNCTION fn_update_so_tran() OWNER TO "AutoDRS";

CREATE TRIGGER trg_update_so_tran AFTER INSERT OR UPDATE on parts_purchasing FOR EACH ROW EXECUTE PROCEDURE fn_update_so_tran();

I'm liking PostgreSQL more and more with each new thing I try :)

Thanks muchly.

--
Paul Lambert
Database Administrator
AutoLedgers


---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

               http://www.postgresql.org/about/donate

Reply via email to