how to create this trigger?

From: Ramiro Arenas Ramírez <ramiroa(at)coordinadora(dot)com(dot)co>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: how to create this trigger?
Date: 2001-02-01 21:48:28
Message-ID: KJEFJKLOGBDOOKFDDKKLMEMGCCAA.ramiroa@coordinadora.com.co
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I need to create a trigger that increment a value in a column
of table1 where a row is inserted in table 2

I have tried whit this but it just does nothing.

CREATE FUNCTION increment_value () RETURNS opaque AS
'DECLARE
code int4;
BEGIN
code := new.code;
UPDATE table1
SET value = value + 1
WHERE id = code;
RETURN NEW;
END;' LANGUAGE 'plpgsql';

CREATE TRIGGER insert_on_table2 BEFORE INSERT ON table2
FOR EACH ROW EXECUTE PROCEDURE increment_value();

Can you help me?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Davis 2001-02-01 21:52:33 RE: how to create this trigger?
Previous Message guard 2001-02-01 18:01:45 how to simulate UPdate ...?