pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedhow to create this trigger?
3+ messages / 3 participants
[nested] [flat]
* how to create this trigger?
@ 2001-02-01 21:48 Ramiro Arenas Ramírez <ramiroa@coordinadora.com.co>
0 siblings, 1 reply; 3+ messages in thread
From: Ramiro Arenas Ramírez @ 2001-02-01 21:48 UTC (permalink / raw)
To: 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?
^ permalink raw reply [nested|flat] 3+ messages in thread
* RE: how to create this trigger?
@ 2001-02-01 21:52 Michael Davis <mdavis@sevainc.com>
0 siblings, 0 replies; 3+ messages in thread
From: Michael Davis @ 2001-02-01 21:52 UTC (permalink / raw)
To: 'Ramiro Arenas Ramirez' <ramiroa@coordinadora.com.co>; pgsql-sql
Did you insert a row into table2? What happens if there is no row in table
1 where id = code (of the newly inserted row in table2). Seems to me you
many need to consider expanding increment_value() to check table1 to see if
code exists. If not insert a new value, else update.
-----Original Message-----
From: Ramiro Arenas Ramirez [SMTP:ramiroa@coordinadora.com.co]
Sent: Thursday, February 01, 2001 2:48 PM
To: pgsql-sql@postgresql.org
Subject: how to create this trigger?
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?
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: how to create this trigger?
@ 2001-02-01 23:08 Albert REINER <areiner@tph.tuwien.ac.at>
parent: Ramiro Arenas Ramírez <ramiroa@coordinadora.com.co>
0 siblings, 0 replies; 3+ messages in thread
From: Albert REINER @ 2001-02-01 23:08 UTC (permalink / raw)
To: 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@tph.tuwien.ac.at>
Deutsch * English * Esperanto * Latine
--------------------------------------------------------------------------
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-02-01 23:08 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-02-01 21:48 how to create this trigger? Ramiro Arenas Ramírez <ramiroa@coordinadora.com.co>
2001-02-01 23:08 ` Albert REINER <areiner@tph.tuwien.ac.at>
2001-02-01 21:52 RE: how to create this trigger? Michael Davis <mdavis@sevainc.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox