pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
trigger on table
5+ messages / 5 participants
[nested] [flat]

* trigger on table
@ 2002-02-14 12:17 Graham Vickrage <graham@digitalplanit.com>
  2002-02-14 12:27 ` Re: trigger on table Hano de la Rouviere <hano@linutech.co.za>
  2002-02-14 12:28 ` Re: trigger on table PGExplorer <pgmail@pgexplorer.com>
  2002-02-14 12:43 ` Re: trigger on table Karel Zak <zakkr@zf.jcu.cz>
  0 siblings, 3 replies; 5+ messages in thread

From: Graham Vickrage @ 2002-02-14 12:17 UTC (permalink / raw)
  To: pgsql-sql

I am trying to create a trigger on a table that simply sets the last_updated
field when any updates are made to that table.

I have tried the following: -

CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS '
BEGIN
UPDATE item SET last_updated = now();
RETURN OLD;
END;' LANGUAGE 'plpgsql';

CREATE TRIGGER item_last_updated AFTER UPDATE ON item
FOR EACH ROW EXECUTE PROCEDURE set_item_last_updated();

When I try to execute this it hangs and postmaster eventually runs out of
memory.

Is there a way to do it just using sql not plpsql?
Why is it hanging?

Thank in advance.

Graham





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: trigger on table
  2002-02-14 12:17 trigger on table Graham Vickrage <graham@digitalplanit.com>
@ 2002-02-14 12:27 ` Hano de la Rouviere <hano@linutech.co.za>
  2 siblings, 0 replies; 5+ messages in thread

From: Hano de la Rouviere @ 2002-02-14 12:27 UTC (permalink / raw)
  To: Graham Vickrage <graham@digitalplanit.com>; pgsql-sql

Try
 CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS '
 BEGIN
 NEW.last_updated = now();
 RETURN NEW;
 END;'
 LANGUAGE 'plpgsql';

 CREATE TRIGGER item_last_updated BEFORE UPDATE ON item
 FOR EACH ROW EXECUTE PROCEDURE set_item_last_updated();

Make sure its BEFORE...

Hope this helps


http://www.pgexplorer.com
GUI Tool for Postgres

----- Original Message -----
From: "Graham Vickrage" <graham@digitalplanit.com>
To: "Postgres SQL" <pgsql-sql@postgresql.org>
Sent: Thursday, February 14, 2002 2:17 PM
Subject: [SQL] trigger on table


> I am trying to create a trigger on a table that simply sets the
last_updated
> field when any updates are made to that table.
>
> I have tried the following: -
>
> CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS '
> BEGIN
> UPDATE item SET last_updated = now();
> RETURN OLD;
> END;' LANGUAGE 'plpgsql';
>
> CREATE TRIGGER item_last_updated AFTER UPDATE ON item
> FOR EACH ROW EXECUTE PROCEDURE set_item_last_updated();
>
> When I try to execute this it hangs and postmaster eventually runs out of
> memory.
>
> Is there a way to do it just using sql not plpsql?
> Why is it hanging?
>
> Thank in advance.
>
> Graham
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: trigger on table
  2002-02-14 12:17 trigger on table Graham Vickrage <graham@digitalplanit.com>
@ 2002-02-14 12:28 ` PGExplorer <pgmail@pgexplorer.com>
  2 siblings, 0 replies; 5+ messages in thread

From: PGExplorer @ 2002-02-14 12:28 UTC (permalink / raw)
  To: Graham Vickrage <graham@digitalplanit.com>; pgsql-sql

Try
 CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS '
 BEGIN
 NEW.last_updated = now();
 RETURN NEW;
 END;'
 LANGUAGE 'plpgsql';

 CREATE TRIGGER item_last_updated BEFORE UPDATE ON item
 FOR EACH ROW EXECUTE PROCEDURE set_item_last_updated();

Make sure its BEFORE...

Hope this helps


http://www.pgexplorer.com
GUI Tool for Postgres

----- Original Message -----
From: "Graham Vickrage" <graham@digitalplanit.com>
To: "Postgres SQL" <pgsql-sql@postgresql.org>
Sent: Thursday, February 14, 2002 2:17 PM
Subject: [SQL] trigger on table


> I am trying to create a trigger on a table that simply sets the
last_updated
> field when any updates are made to that table.
>
> I have tried the following: -
>
> CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS '
> BEGIN
> UPDATE item SET last_updated = now();
> RETURN OLD;
> END;' LANGUAGE 'plpgsql';
>
> CREATE TRIGGER item_last_updated AFTER UPDATE ON item
> FOR EACH ROW EXECUTE PROCEDURE set_item_last_updated();
>
> When I try to execute this it hangs and postmaster eventually runs out of
> memory.
>
> Is there a way to do it just using sql not plpsql?
> Why is it hanging?
>
> Thank in advance.
>
> Graham
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: trigger on table
  2002-02-14 12:17 trigger on table Graham Vickrage <graham@digitalplanit.com>
@ 2002-02-14 12:43 ` Karel Zak <zakkr@zf.jcu.cz>
  2002-02-15 01:04   ` Re: trigger on table Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2 siblings, 1 reply; 5+ messages in thread

From: Karel Zak @ 2002-02-14 12:43 UTC (permalink / raw)
  To: Graham Vickrage <graham@digitalplanit.com>; +Cc: pgsql-sql

On Thu, Feb 14, 2002 at 12:17:02PM -0000, Graham Vickrage wrote:
> I am trying to create a trigger on a table that simply sets the last_updated
> field when any updates are made to that table.
> 
> I have tried the following: -
> 
> CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS '
> BEGIN
> UPDATE item SET last_updated = now();
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> RETURN OLD;
> END;' LANGUAGE 'plpgsql';
> 
> CREATE TRIGGER item_last_updated AFTER UPDATE ON item
                                  ^^^^^^^
> FOR EACH ROW EXECUTE PROCEDURE set_item_last_updated();
> 
> When I try to execute this it hangs and postmaster eventually runs out of
> memory.

 You create trigger on update and inside this trigger you do update 
again. It's cycle...
 
> Is there a way to do it just using sql not plpsql?

 It works with PL/SQL, try:

 CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS '
        BEGIN
                NEW.last_updated := ''now'';
                RETURN NEW;
        END;
' LANGUAGE 'plpgsql';

 CREATE TRIGGER item_last_updated BEFORE UPDATE ON item
 FOR EACH ROW EXECUTE PROCEDURE set_item_last_updated ();

        Karel

-- 
 Karel Zak  <zakkr@zf.jcu.cz>
 http://home.zf.jcu.cz/~zakkr/
 
 C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: trigger on table
  2002-02-14 12:17 trigger on table Graham Vickrage <graham@digitalplanit.com>
  2002-02-14 12:43 ` Re: trigger on table Karel Zak <zakkr@zf.jcu.cz>
@ 2002-02-15 01:04   ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 0 replies; 5+ messages in thread

From: Christopher Kings-Lynne @ 2002-02-15 01:04 UTC (permalink / raw)
  To: Karel Zak <zakkr@zf.jcu.cz>; Graham Vickrage <graham@digitalplanit.com>; +Cc: pgsql-sql

> > I have tried the following: -
> >
> > CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS '
> > BEGIN
> > UPDATE item SET last_updated = now();
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > RETURN OLD;
> > END;' LANGUAGE 'plpgsql';

Even better I guess, if you are running 7.1 or greater, use
CURRENT_TIMESTAMP instead of now()?

Chris




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2002-02-15 01:04 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-14 12:17 trigger on table Graham Vickrage <graham@digitalplanit.com>
2002-02-14 12:27 ` Hano de la Rouviere <hano@linutech.co.za>
2002-02-14 12:28 ` PGExplorer <pgmail@pgexplorer.com>
2002-02-14 12:43 ` Karel Zak <zakkr@zf.jcu.cz>
2002-02-15 01:04   ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>

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