pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Negandhi, Nishith <Nishith.Negandhi@infoUSA.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Error in trigger
Date: Thu, 18 Jan 2007 19:16:26 -0800 (PST)
Message-ID: <20070118191415.Y43232@megazone.bigpanda.com> (raw)
In-Reply-To: <FE0C41EEBEF01C47BF3A91F60669446804973253@PUNISHER.intra.infousa.com>
References: <FE0C41EEBEF01C47BF3A91F60669446804973253@PUNISHER.intra.infousa.com>


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).



view thread (2+ messages)

Message-ID: <20070118191415.Y43232@megazone.bigpanda.com>
Permalink:  ../20070118191415.Y43232@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20070118191415.Y43232@megazone.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: sszabo@megazone.bigpanda.com, Nishith.Negandhi@infoUSA.com
  Subject: Re: Error in trigger
  In-Reply-To: <20070118191415.Y43232@megazone.bigpanda.com>
  References: <FE0C41EEBEF01C47BF3A91F60669446804973253@PUNISHER.intra.infousa.com> <20070118191415.Y43232@megazone.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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