Re: how to create this trigger?

From: "Albert REINER" <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to create this trigger?
Date: 2001-02-01 23:08:41
Message-ID: 20010202000841.A1197@frithjof
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Don't know much, but couldn't you let increment_value take an argument
and run it on new.code?

But maybe I am completely off.

Albert.

On Thu, Feb 01, 2001 at 04:48:28PM -0500, Ramiro Arenas Ramírez wrote:
> 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?
>
>
>
>

--

--------------------------------------------------------------------------
Albert Reiner <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
Deutsch * English * Esperanto * Latine
--------------------------------------------------------------------------

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ross J. Reedstrom 2001-02-01 23:59:26 Re: Permissions for foreign keys
Previous Message Brice Ruth 2001-02-01 22:57:44 SQL Join - MySQL/PostgreSQL difference?