Skip site navigation (1) Skip section navigation (2)

Re: Error in trigger

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: "Negandhi, Nishith" <Nishith(dot)Negandhi(at)infoUSA(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Error in trigger
Date: 2007-01-19 03:16:26
Message-ID: 20070118191415.Y43232@megazone.bigpanda.com (view raw or flat)
Thread:
Lists: pgsql-admin
On Thu, 18 Jan 2007, Negandhi, Nishith wrote:

> Hi,
> All my tables in the database have "CreateDate" and "LastUpdateDate"
> columns. I need to create a trigger wherein on insert the "CreateDate"
> column is inserted with the current date. On Update the "LastUpdateDate"
> is inserted with the current date.
>
> I tried the insert trigger as mentioned below:
>
> CREATE FUNCTION "CreateDate_F"() RETURNS TRIGGER AS $CreateDate_T$
> BEGIN
> insert into "CreateDate" values (CURRENT_TIMESTAMP);
> END;
> $CreateDate_T$ LANGUAGE plpgsql;
>
> CREATE TRIGGER "Create_Date_T" AFTER INSERT ON "CreateDate"
> FOR EACH STATEMENT EXECUTE PROCEDURE "CreateDate_F"();

I think you really want to be using a before row trigger and setting
NEW."CreateDate" in it if you want each row to have the appropriate
creation date (and a similar thing for the update date).

In response to

pgsql-admin by date

Next:From: Gregory S. WilliamsonDate: 2007-01-19 03:34:42
Subject: Re: Strange performance hit upgrading from 8.0.9 to 8.2.1
Previous:From: David F. SkollDate: 2007-01-19 01:37:33
Subject: Strange performance hit upgrading from 8.0.9 to 8.2.1

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group